mirror of
https://github.com/lua/lua
synced 2024-11-26 06:39:41 +03:00
added structure for local-variable information to allow extra
checkings if needed
This commit is contained in:
parent
24359ae294
commit
198be23f36
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.56 2007/10/25 16:45:47 roberto Exp roberto $
|
** $Id: lparser.c,v 2.57 2008/04/02 17:19:22 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
|
#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
|
||||||
|
|
||||||
#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]])
|
#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i].idx])
|
||||||
|
|
||||||
#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
|
#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
|
||||||
|
|
||||||
@ -161,8 +161,9 @@ static int registerlocalvar (LexState *ls, TString *varname) {
|
|||||||
|
|
||||||
static void new_localvar (LexState *ls, TString *name, int n) {
|
static void new_localvar (LexState *ls, TString *name, int n) {
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
|
int reg = registerlocalvar(ls, name);
|
||||||
luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
|
luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
|
||||||
fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name));
|
fs->actvar[fs->nactvar+n].idx = cast(unsigned short, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
14
lparser.h
14
lparser.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp roberto $
|
** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -23,8 +23,8 @@ typedef enum {
|
|||||||
VFALSE,
|
VFALSE,
|
||||||
VK, /* info = index of constant in `k' */
|
VK, /* info = index of constant in `k' */
|
||||||
VKNUM, /* nval = numerical value */
|
VKNUM, /* nval = numerical value */
|
||||||
VLOCAL, /* info = local register */
|
VLOCAL, /* info = local register; aux = read only */
|
||||||
VUPVAL, /* info = index of upvalue in `upvalues' */
|
VUPVAL, /* info = index of upvalue in 'upvalues'; aux = read only */
|
||||||
VGLOBAL, /* info = index of table; aux = index of global name in `k' */
|
VGLOBAL, /* info = index of table; aux = index of global name in `k' */
|
||||||
VINDEXED, /* info = table register; aux = index register (or `k') */
|
VINDEXED, /* info = table register; aux = index register (or `k') */
|
||||||
VJMP, /* info = instruction pc */
|
VJMP, /* info = instruction pc */
|
||||||
@ -34,6 +34,7 @@ typedef enum {
|
|||||||
VVARARG /* info = instruction pc */
|
VVARARG /* info = instruction pc */
|
||||||
} expkind;
|
} expkind;
|
||||||
|
|
||||||
|
|
||||||
typedef struct expdesc {
|
typedef struct expdesc {
|
||||||
expkind k;
|
expkind k;
|
||||||
union {
|
union {
|
||||||
@ -51,6 +52,11 @@ typedef struct upvaldesc {
|
|||||||
} upvaldesc;
|
} upvaldesc;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct vardesc {
|
||||||
|
unsigned short idx;
|
||||||
|
} vardesc;
|
||||||
|
|
||||||
|
|
||||||
struct BlockCnt; /* defined in lparser.c */
|
struct BlockCnt; /* defined in lparser.c */
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +77,7 @@ typedef struct FuncState {
|
|||||||
short nlocvars; /* number of elements in `locvars' */
|
short nlocvars; /* number of elements in `locvars' */
|
||||||
lu_byte nactvar; /* number of active local variables */
|
lu_byte nactvar; /* number of active local variables */
|
||||||
upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
|
upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
|
||||||
unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
|
vardesc actvar[LUAI_MAXVARS]; /* declared-variable stack */
|
||||||
} FuncState;
|
} FuncState;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user