Browse Source

no need to keep "_ENV" name in global state (can be kept in lex state)

pull/9/head
Roberto Ierusalimschy 15 years ago
parent
commit
6abde1b05a
  1. 4
      llex.c
  2. 3
      llex.h
  3. 10
      lparser.c
  4. 4
      lstate.c
  5. 3
      lstate.h

4
llex.c

@ -1,5 +1,5 @@
/* /*
** $Id: llex.c,v 2.34 2009/11/17 16:33:38 roberto Exp roberto $ ** $Id: llex.c,v 2.35 2010/02/27 21:16:24 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -152,6 +152,8 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
ls->linenumber = 1; ls->linenumber = 1;
ls->lastline = 1; ls->lastline = 1;
ls->source = source; ls->source = source;
ls->envn = luaS_new(L, "_ENV");
luaS_fix(ls->envn); /* never collect this name */
luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
next(ls); /* read first char */ next(ls); /* read first char */
} }

3
llex.h

@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.63 2010/03/08 16:55:52 roberto Exp roberto $ ** $Id: llex.h,v 1.64 2010/03/13 15:55:42 roberto Exp roberto $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -60,6 +60,7 @@ typedef struct LexState {
Mbuffer *buff; /* buffer for tokens */ Mbuffer *buff; /* buffer for tokens */
struct Varlist *varl; /* list of all active local variables */ struct Varlist *varl; /* list of all active local variables */
TString *source; /* current source name */ TString *source; /* current source name */
TString *envn; /* environment variable name */
char decpoint; /* locale decimal point */ char decpoint; /* locale decimal point */
} LexState; } LexState;

10
lparser.c

@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 2.80 2010/03/13 15:55:42 roberto Exp roberto $ ** $Id: lparser.c,v 2.81 2010/04/05 16:26:37 roberto Exp roberto $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -288,7 +288,7 @@ static void singlevar (LexState *ls, expdesc *var) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
expdesc key; expdesc key;
singlevaraux(fs, G(ls->L)->envn, var, 1); /* get _ENV variable */ singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */
lua_assert(var->k == VLOCAL || var->k == VUPVAL); lua_assert(var->k == VLOCAL || var->k == VUPVAL);
codestring(ls, &key, varname); /* key is variable name */ codestring(ls, &key, varname); /* key is variable name */
luaK_indexed(fs, var, &key); /* env[varname] */ luaK_indexed(fs, var, &key); /* env[varname] */
@ -429,12 +429,12 @@ static void close_func (LexState *ls) {
** opens the main function, which is a regular vararg function with an ** opens the main function, which is a regular vararg function with an
** upvalue named '_ENV' ** upvalue named '_ENV'
*/ */
static void open_mainfunc (lua_State *L, LexState *ls, FuncState *fs) { static void open_mainfunc (LexState *ls, FuncState *fs) {
expdesc v; expdesc v;
open_func(ls, fs); open_func(ls, fs);
fs->f->is_vararg = 1; /* main function is always vararg */ fs->f->is_vararg = 1; /* main function is always vararg */
init_exp(&v, VLOCAL, 0); init_exp(&v, VLOCAL, 0);
newupvalue(fs, G(L)->envn, &v); /* create '_ENV' upvalue */ newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */
} }
@ -448,7 +448,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Varlist *varl,
lexstate.buff = buff; lexstate.buff = buff;
lexstate.varl = varl; lexstate.varl = varl;
luaX_setinput(L, &lexstate, z, tname); luaX_setinput(L, &lexstate, z, tname);
open_mainfunc(L, &lexstate, &funcstate); open_mainfunc(&lexstate, &funcstate);
luaX_next(&lexstate); /* read first token */ luaX_next(&lexstate); /* read first token */
chunk(&lexstate); /* read main chunk */ chunk(&lexstate); /* read main chunk */
check(&lexstate, TK_EOS); check(&lexstate, TK_EOS);

4
lstate.c

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 2.75 2010/03/26 20:58:11 roberto Exp roberto $ ** $Id: lstate.c,v 2.76 2010/03/29 17:43:14 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -157,8 +157,6 @@ static void f_luaopen (lua_State *L, void *ud) {
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
luaT_init(L); luaT_init(L);
luaX_init(L); luaX_init(L);
g->envn = luaS_new(L, "_ENV");
luaS_fix(g->envn); /* never collect this name */
luaS_fix(luaS_newliteral(L, MEMERRMSG)); luaS_fix(luaS_newliteral(L, MEMERRMSG));
g->GCthreshold = 4*g->totalbytes; g->GCthreshold = 4*g->totalbytes;
} }

3
lstate.h

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.h,v 2.58 2010/03/26 20:58:11 roberto Exp roberto $ ** $Id: lstate.h,v 2.59 2010/03/29 17:43:14 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -142,7 +142,6 @@ typedef struct global_State {
lua_CFunction panic; /* to be called in unprotected errors */ lua_CFunction panic; /* to be called in unprotected errors */
struct lua_State *mainthread; struct lua_State *mainthread;
const lua_Number *version; /* pointer to version number */ const lua_Number *version; /* pointer to version number */
TString *envn; /* environment variable name */
TString *tmname[TM_N]; /* array with tag-method names */ TString *tmname[TM_N]; /* array with tag-method names */
struct Table *mt[NUM_TAGS]; /* metatables for basic types */ struct Table *mt[NUM_TAGS]; /* metatables for basic types */
} global_State; } global_State;

Loading…
Cancel
Save