From c85162be276f7bb95416c5ec0ecefd9c24877d67 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 22 Aug 2000 14:44:17 -0300 Subject: new way to store local-variable information. --- lfunc.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'lfunc.c') diff --git a/lfunc.c b/lfunc.c index 9e8d3a67..579d5e6a 100644 --- a/lfunc.c +++ b/lfunc.c @@ -1,5 +1,5 @@ /* -** $Id: lfunc.c,v 1.28 2000/08/08 20:42:07 roberto Exp roberto $ +** $Id: lfunc.c,v 1.29 2000/08/09 19:16:57 roberto Exp roberto $ ** Auxiliary functions to manipulate prototypes and closures ** See Copyright Notice in lua.h */ @@ -43,6 +43,7 @@ Proto *luaF_newproto (lua_State *L) { f->kproto = NULL; f->nkproto = 0; f->locvars = NULL; + f->nlocvars = 0; f->next = L->rootproto; L->rootproto = f; f->marked = 0; @@ -73,19 +74,15 @@ void luaF_freeclosure (lua_State *L, Closure *c) { ** Look for n-th local variable at line `line' in function `func'. ** Returns NULL if not found. */ -const char *luaF_getlocalname (const Proto *func, int local_number, int pc) { - int count = 0; - const char *varname = NULL; - LocVar *lv = func->locvars; - for (; lv->pc != -1 && lv->pc <= pc; lv++) { - if (lv->varname) { /* register */ - if (++count == local_number) - varname = lv->varname->str; +const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { + int i; + for (i = 0; inlocvars && f->locvars[i].startpc <= pc; i++) { + if (pc < f->locvars[i].endpc) { /* is variable active? */ + local_number--; + if (local_number == 0) + return f->locvars[i].varname->str; } - else /* unregister */ - if (--count < local_number) - varname = NULL; } - return varname; + return NULL; /* not found */ } -- cgit v1.2.3-55-g6feb