aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-05-08 12:44:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-05-08 12:44:51 -0300
commit198be23f36466496228bdbceac2d4b8c01e3c21c (patch)
tree5ab668d122cbd557b2d0e7a8a82e636a070f179f
parent24359ae2945d0c9bd341598420f5f7678e1d1a03 (diff)
downloadlua-198be23f36466496228bdbceac2d4b8c01e3c21c.tar.gz
lua-198be23f36466496228bdbceac2d4b8c01e3c21c.tar.bz2
lua-198be23f36466496228bdbceac2d4b8c01e3c21c.zip
added structure for local-variable information to allow extra
checkings if needed
-rw-r--r--lparser.c7
-rw-r--r--lparser.h14
2 files changed, 14 insertions, 7 deletions
diff --git a/lparser.c b/lparser.c
index f0debe73..61032552 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.56 2007/10/25 16:45:47 roberto Exp roberto $ 2** $Id: lparser.c,v 2.57 2008/04/02 17:19:22 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*/
@@ -29,7 +29,7 @@
29 29
30#define hasmultret(k) ((k) == VCALL || (k) == VVARARG) 30#define hasmultret(k) ((k) == VCALL || (k) == VVARARG)
31 31
32#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) 32#define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i].idx])
33 33
34#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m) 34#define luaY_checklimit(fs,v,l,m) if ((v)>(l)) errorlimit(fs,l,m)
35 35
@@ -161,8 +161,9 @@ static int registerlocalvar (LexState *ls, TString *varname) {
161 161
162static void new_localvar (LexState *ls, TString *name, int n) { 162static void new_localvar (LexState *ls, TString *name, int n) {
163 FuncState *fs = ls->fs; 163 FuncState *fs = ls->fs;
164 int reg = registerlocalvar(ls, name);
164 luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables"); 165 luaY_checklimit(fs, fs->nactvar+n+1, LUAI_MAXVARS, "local variables");
165 fs->actvar[fs->nactvar+n] = cast(unsigned short, registerlocalvar(ls, name)); 166 fs->actvar[fs->nactvar+n].idx = cast(unsigned short, reg);
166} 167}
167 168
168 169
diff --git a/lparser.h b/lparser.h
index 7e1d487d..0e06b1ad 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.56 2005/10/03 14:02:40 roberto Exp roberto $ 2** $Id: lparser.h,v 1.57 2006/03/09 18:14:31 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*/
@@ -23,8 +23,8 @@ typedef enum {
23 VFALSE, 23 VFALSE,
24 VK, /* info = index of constant in `k' */ 24 VK, /* info = index of constant in `k' */
25 VKNUM, /* nval = numerical value */ 25 VKNUM, /* nval = numerical value */
26 VLOCAL, /* info = local register */ 26 VLOCAL, /* info = local register; aux = read only */
27 VUPVAL, /* info = index of upvalue in `upvalues' */ 27 VUPVAL, /* info = index of upvalue in 'upvalues'; aux = read only */
28 VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 28 VGLOBAL, /* info = index of table; aux = index of global name in `k' */
29 VINDEXED, /* info = table register; aux = index register (or `k') */ 29 VINDEXED, /* info = table register; aux = index register (or `k') */
30 VJMP, /* info = instruction pc */ 30 VJMP, /* info = instruction pc */
@@ -34,6 +34,7 @@ typedef enum {
34 VVARARG /* info = instruction pc */ 34 VVARARG /* info = instruction pc */
35} expkind; 35} expkind;
36 36
37
37typedef struct expdesc { 38typedef struct expdesc {
38 expkind k; 39 expkind k;
39 union { 40 union {
@@ -51,6 +52,11 @@ typedef struct upvaldesc {
51} upvaldesc; 52} upvaldesc;
52 53
53 54
55typedef struct vardesc {
56 unsigned short idx;
57} vardesc;
58
59
54struct BlockCnt; /* defined in lparser.c */ 60struct BlockCnt; /* defined in lparser.c */
55 61
56 62
@@ -71,7 +77,7 @@ typedef struct FuncState {
71 short nlocvars; /* number of elements in `locvars' */ 77 short nlocvars; /* number of elements in `locvars' */
72 lu_byte nactvar; /* number of active local variables */ 78 lu_byte nactvar; /* number of active local variables */
73 upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ 79 upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
74 unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ 80 vardesc actvar[LUAI_MAXVARS]; /* declared-variable stack */
75} FuncState; 81} FuncState;
76 82
77 83