aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-11 08:46:24 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-11 08:46:24 -0200
commit7a40cdbda0a171da223094208dd3c6e3eca13922 (patch)
treec95840411ac26e11b0683d4a5fc88402c1d0a70a
parent3cdeacbbfba9308dd2dcc995a9bcc510bfcead31 (diff)
downloadlua-7a40cdbda0a171da223094208dd3c6e3eca13922.tar.gz
lua-7a40cdbda0a171da223094208dd3c6e3eca13922.tar.bz2
lua-7a40cdbda0a171da223094208dd3c6e3eca13922.zip
different variables for number of upvalues and size of upvalue array
(makes code clearer)
-rw-r--r--lapi.c8
-rw-r--r--ldebug.c6
-rw-r--r--ldump.c11
-rw-r--r--lfunc.c7
-rw-r--r--lgc.c6
-rw-r--r--lobject.h5
-rw-r--r--lparser.c27
-rw-r--r--lparser.h3
-rw-r--r--lundump.c21
-rw-r--r--lvm.c4
10 files changed, 43 insertions, 55 deletions
diff --git a/lapi.c b/lapi.c
index 998bac0a..b413ada7 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.226 2002/12/04 17:38:31 roberto Exp roberto $ 2** $Id: lapi.c,v 1.227 2002/12/19 11:11:55 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -872,14 +872,16 @@ static const char *aux_upvalue (lua_State *L, int funcindex, int n,
872 StkId fi = luaA_index(L, funcindex); 872 StkId fi = luaA_index(L, funcindex);
873 if (!ttisfunction(fi)) return NULL; 873 if (!ttisfunction(fi)) return NULL;
874 f = clvalue(fi); 874 f = clvalue(fi);
875 if (n > f->l.nupvalues) return NULL;
876 if (f->c.isC) { 875 if (f->c.isC) {
876 if (n > f->c.nupvalues) return NULL;
877 *val = &f->c.upvalue[n-1]; 877 *val = &f->c.upvalue[n-1];
878 return ""; 878 return "";
879 } 879 }
880 else { 880 else {
881 Proto *p = f->l.p;
882 if (n > p->sizeupvalues) return NULL;
881 *val = f->l.upvals[n-1]->v; 883 *val = f->l.upvals[n-1]->v;
882 return getstr(f->l.p->upvalues[n-1]); 884 return getstr(p->upvalues[n-1]);
883 } 885 }
884} 886}
885 887
diff --git a/ldebug.c b/ldebug.c
index bf58d0a8..754efe1f 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.142 2002/12/06 17:15:35 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.143 2002/12/11 12:34:22 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -345,7 +345,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
345 } 345 }
346 case OP_GETUPVAL: 346 case OP_GETUPVAL:
347 case OP_SETUPVAL: { 347 case OP_SETUPVAL: {
348 check(b < pt->nupvalues); 348 check(b < pt->nups);
349 break; 349 break;
350 } 350 }
351 case OP_GETGLOBAL: 351 case OP_GETGLOBAL:
@@ -404,7 +404,7 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
404 case OP_CLOSURE: { 404 case OP_CLOSURE: {
405 int nup; 405 int nup;
406 check(b < pt->sizep); 406 check(b < pt->sizep);
407 nup = pt->p[b]->nupvalues; 407 nup = pt->p[b]->nups;
408 check(pc + nup < pt->sizecode); 408 check(pc + nup < pt->sizecode);
409 for (; nup>0; nup--) { 409 for (; nup>0; nup--) {
410 OpCode op1 = GET_OPCODE(pt->code[pc+nup]); 410 OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
diff --git a/ldump.c b/ldump.c
index f62eb2c1..a34aeed3 100644
--- a/ldump.c
+++ b/ldump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldump.c,v 1.3 2003/01/10 11:08:45 lhf Exp $ 2** $Id: ldump.c,v 1.3 2003/01/27 15:52:57 roberto Exp roberto $
3** save bytecodes 3** save bytecodes
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -90,14 +90,9 @@ static void DumpLines(const Proto* f, DumpState* D)
90 90
91static void DumpUpvalues(const Proto* f, DumpState* D) 91static void DumpUpvalues(const Proto* f, DumpState* D)
92{ 92{
93 if (f->upvalues==NULL) 93 int i,n=f->sizeupvalues;
94 DumpInt(0,D);
95 else
96 {
97 int i,n=f->nupvalues;
98 DumpInt(n,D); 94 DumpInt(n,D);
99 for (i=0; i<n; i++) DumpString(f->upvalues[i],D); 95 for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
100 }
101} 96}
102 97
103static void DumpFunction(const Proto* f, const TString* p, DumpState* D); 98static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
@@ -133,7 +128,7 @@ static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
133{ 128{
134 DumpString((f->source==p) ? NULL : f->source,D); 129 DumpString((f->source==p) ? NULL : f->source,D);
135 DumpInt(f->lineDefined,D); 130 DumpInt(f->lineDefined,D);
136 DumpInt(f->nupvalues,D); 131 DumpByte(f->nups,D);
137 DumpByte(f->numparams,D); 132 DumpByte(f->numparams,D);
138 DumpByte(f->is_vararg,D); 133 DumpByte(f->is_vararg,D);
139 DumpByte(f->maxstacksize,D); 134 DumpByte(f->maxstacksize,D);
diff --git a/lfunc.c b/lfunc.c
index e55b59d9..2ce2f047 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.64 2002/12/04 17:38:31 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.65 2002/12/19 11:11:55 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -84,7 +84,8 @@ Proto *luaF_newproto (lua_State *L) {
84 f->code = NULL; 84 f->code = NULL;
85 f->sizecode = 0; 85 f->sizecode = 0;
86 f->sizelineinfo = 0; 86 f->sizelineinfo = 0;
87 f->nupvalues = 0; 87 f->sizeupvalues = 0;
88 f->nups = 0;
88 f->upvalues = NULL; 89 f->upvalues = NULL;
89 f->numparams = 0; 90 f->numparams = 0;
90 f->is_vararg = 0; 91 f->is_vararg = 0;
@@ -104,7 +105,7 @@ void luaF_freeproto (lua_State *L, Proto *f) {
104 luaM_freearray(L, f->k, f->sizek, TObject); 105 luaM_freearray(L, f->k, f->sizek, TObject);
105 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); 106 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
106 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); 107 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
107 luaM_freearray(L, f->upvalues, f->nupvalues, TString *); 108 luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
108 luaM_freelem(L, f); 109 luaM_freelem(L, f);
109} 110}
110 111
diff --git a/lgc.c b/lgc.c
index 626756a7..01e8032f 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.167 2002/12/19 11:11:55 roberto Exp roberto $ 2** $Id: lgc.c,v 1.168 2003/02/10 17:32:50 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -190,7 +190,7 @@ static void traverseproto (GCState *st, Proto *f) {
190 if (ttisstring(f->k+i)) 190 if (ttisstring(f->k+i))
191 stringmark(tsvalue(f->k+i)); 191 stringmark(tsvalue(f->k+i));
192 } 192 }
193 for (i=0; i<f->nupvalues; i++) /* mark upvalue names */ 193 for (i=0; i<f->sizeupvalues; i++) /* mark upvalue names */
194 stringmark(f->upvalues[i]); 194 stringmark(f->upvalues[i]);
195 for (i=0; i<f->sizep; i++) /* mark nested protos */ 195 for (i=0; i<f->sizep; i++) /* mark nested protos */
196 markvalue(st, f->p[i]); 196 markvalue(st, f->p[i]);
@@ -209,7 +209,7 @@ static void traverseclosure (GCState *st, Closure *cl) {
209 } 209 }
210 else { 210 else {
211 int i; 211 int i;
212 lua_assert(cl->l.nupvalues == cl->l.p->nupvalues); 212 lua_assert(cl->l.nupvalues == cl->l.p->nups);
213 markvalue(st, hvalue(&cl->l.g)); 213 markvalue(st, hvalue(&cl->l.g));
214 markvalue(st, cl->l.p); 214 markvalue(st, cl->l.p);
215 for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */ 215 for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */
diff --git a/lobject.h b/lobject.h
index 6b00b4b6..90533240 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.155 2002/11/14 16:16:21 roberto Exp roberto $ 2** $Id: lobject.h,v 1.156 2002/12/19 11:11:55 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -216,7 +216,7 @@ typedef struct Proto {
216 struct LocVar *locvars; /* information about local variables */ 216 struct LocVar *locvars; /* information about local variables */
217 TString **upvalues; /* upvalue names */ 217 TString **upvalues; /* upvalue names */
218 TString *source; 218 TString *source;
219 int nupvalues; /* (also size of `upvals') */ 219 int sizeupvalues;
220 int sizek; /* size of `k' */ 220 int sizek; /* size of `k' */
221 int sizecode; 221 int sizecode;
222 int sizelineinfo; 222 int sizelineinfo;
@@ -224,6 +224,7 @@ typedef struct Proto {
224 int sizelocvars; 224 int sizelocvars;
225 int lineDefined; 225 int lineDefined;
226 GCObject *gclist; 226 GCObject *gclist;
227 lu_byte nups; /* number of upvalues */
227 lu_byte numparams; 228 lu_byte numparams;
228 lu_byte is_vararg; 229 lu_byte is_vararg;
229 lu_byte maxstacksize; 230 lu_byte maxstacksize;
diff --git a/lparser.c b/lparser.c
index d804e430..fb98ebc8 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.202 2002/12/11 12:34:22 roberto Exp roberto $ 2** $Id: lparser.c,v 1.203 2002/12/19 11:11:55 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*/
@@ -181,19 +181,20 @@ static void create_local (LexState *ls, const char *name) {
181 181
182static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { 182static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
183 int i; 183 int i;
184 for (i=0; i<fs->nu; i++) { 184 Proto *f = fs->f;
185 for (i=0; i<f->nups; i++) {
185 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->info) { 186 if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->info) {
186 lua_assert(fs->f->upvalues[i] == name); 187 lua_assert(fs->f->upvalues[i] == name);
187 return i; 188 return i;
188 } 189 }
189 } 190 }
190 /* new one */ 191 /* new one */
191 luaX_checklimit(fs->ls, fs->nu + 1, MAXUPVALUES, "upvalues"); 192 luaX_checklimit(fs->ls, f->nups + 1, MAXUPVALUES, "upvalues");
192 luaM_growvector(fs->L, fs->f->upvalues, fs->nu, fs->f->nupvalues, 193 luaM_growvector(fs->L, fs->f->upvalues, f->nups, fs->f->sizeupvalues,
193 TString *, MAX_INT, ""); 194 TString *, MAX_INT, "");
194 fs->f->upvalues[fs->nu] = name; 195 fs->f->upvalues[f->nups] = name;
195 fs->upvalues[fs->nu] = *v; 196 fs->upvalues[f->nups] = *v;
196 return fs->nu++; 197 return f->nups++;
197} 198}
198 199
199 200
@@ -307,7 +308,7 @@ static void pushclosure (LexState *ls, FuncState *func, expdesc *v) {
307 MAXARG_Bx, "constant table overflow"); 308 MAXARG_Bx, "constant table overflow");
308 f->p[fs->np++] = func->f; 309 f->p[fs->np++] = func->f;
309 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1)); 310 init_exp(v, VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs->np-1));
310 for (i=0; i<func->nu; i++) { 311 for (i=0; i<func->f->nups; i++) {
311 OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; 312 OpCode o = (func->upvalues[i].k == VLOCAL) ? OP_MOVE : OP_GETUPVAL;
312 luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0); 313 luaK_codeABC(fs, o, 0, func->upvalues[i].info, 0);
313 } 314 }
@@ -326,17 +327,13 @@ static void open_func (LexState *ls, FuncState *fs) {
326 fs->jpc = NO_JUMP; 327 fs->jpc = NO_JUMP;
327 fs->freereg = 0; 328 fs->freereg = 0;
328 fs->nk = 0; 329 fs->nk = 0;
329 fs->nu = 0;
330 fs->h = luaH_new(ls->L, 0, 0); 330 fs->h = luaH_new(ls->L, 0, 0);
331 fs->np = 0; 331 fs->np = 0;
332 fs->nlocvars = 0; 332 fs->nlocvars = 0;
333 fs->nactvar = 0; 333 fs->nactvar = 0;
334 fs->bl = NULL; 334 fs->bl = NULL;
335 f->code = NULL;
336 f->source = ls->source; 335 f->source = ls->source;
337 f->maxstacksize = 2; /* registers 0/1 are always valid */ 336 f->maxstacksize = 2; /* registers 0/1 are always valid */
338 f->numparams = 0; /* default for main chunk */
339 f->is_vararg = 0; /* default for main chunk */
340} 337}
341 338
342 339
@@ -356,8 +353,8 @@ static void close_func (LexState *ls) {
356 f->sizep = fs->np; 353 f->sizep = fs->np;
357 luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); 354 luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
358 f->sizelocvars = fs->nlocvars; 355 f->sizelocvars = fs->nlocvars;
359 luaM_reallocvector(L, f->upvalues, f->nupvalues, fs->nu, TString *); 356 luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
360 f->nupvalues = fs->nu; 357 f->sizeupvalues = f->nups;
361 lua_assert(luaG_checkcode(f)); 358 lua_assert(luaG_checkcode(f));
362 lua_assert(fs->bl == NULL); 359 lua_assert(fs->bl == NULL);
363 ls->fs = fs->prev; 360 ls->fs = fs->prev;
@@ -376,7 +373,7 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) {
376 check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); 373 check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected");
377 close_func(&lexstate); 374 close_func(&lexstate);
378 lua_assert(funcstate.prev == NULL); 375 lua_assert(funcstate.prev == NULL);
379 lua_assert(funcstate.nu == 0); 376 lua_assert(funcstate.f->nups == 0);
380 lua_assert(lexstate.nestlevel == 0); 377 lua_assert(lexstate.nestlevel == 0);
381 return funcstate.f; 378 return funcstate.f;
382} 379}
diff --git a/lparser.h b/lparser.h
index b426c800..b5aa740a 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.45 2002/10/08 18:46:08 roberto Exp roberto $ 2** $Id: lparser.h,v 1.46 2002/12/19 11:11:55 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*/
@@ -58,7 +58,6 @@ typedef struct FuncState {
58 int freereg; /* first free register */ 58 int freereg; /* first free register */
59 int nk; /* number of elements in `k' */ 59 int nk; /* number of elements in `k' */
60 int np; /* number of elements in `p' */ 60 int np; /* number of elements in `p' */
61 int nu; /* number of elements in `upvalues' */
62 int nlocvars; /* number of elements in `locvars' */ 61 int nlocvars; /* number of elements in `locvars' */
63 int nactvar; /* number of active local variables */ 62 int nactvar; /* number of active local variables */
64 expdesc upvalues[MAXUPVALUES]; /* upvalues */ 63 expdesc upvalues[MAXUPVALUES]; /* upvalues */
diff --git a/lundump.c b/lundump.c
index 27d1c049..a35d2e9c 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.47 2003/01/10 11:08:45 lhf Exp $ 2** $Id: lundump.c,v 1.59 2003/01/27 15:52:57 roberto Exp roberto $
3** load pre-compiled Lua chunks 3** load pre-compiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -140,21 +140,14 @@ static void LoadLines (LoadState* S, Proto* f)
140 140
141static void LoadUpvalues (LoadState* S, Proto* f) 141static void LoadUpvalues (LoadState* S, Proto* f)
142{ 142{
143 int i,n,noname; 143 int i,n;
144 n=LoadInt(S); 144 n=LoadInt(S);
145 noname=(n==0); 145 if (n!=0 && n!=f->nups)
146 if (!noname && n!=f->nupvalues)
147 luaG_runerror(S->L,"bad nupvalues in %s: read %d; expected %d", 146 luaG_runerror(S->L,"bad nupvalues in %s: read %d; expected %d",
148 S->name,n,f->nupvalues); 147 S->name,n,f->nups);
149 n=f->nupvalues;
150 f->upvalues=luaM_newvector(S->L,n,TString*); 148 f->upvalues=luaM_newvector(S->L,n,TString*);
151 if (noname) 149 f->sizeupvalues = n;
152 { 150 for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
153 TString* name=luaS_newliteral(S->L,"(no name)");
154 for (i=0; i<n; i++) f->upvalues[i]=name;
155 }
156 else
157 for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
158} 151}
159 152
160static Proto* LoadFunction (LoadState* S, TString* p); 153static Proto* LoadFunction (LoadState* S, TString* p);
@@ -196,7 +189,7 @@ static Proto* LoadFunction (LoadState* S, TString* p)
196 Proto* f=luaF_newproto(S->L); 189 Proto* f=luaF_newproto(S->L);
197 f->source=LoadString(S); if (f->source==NULL) f->source=p; 190 f->source=LoadString(S); if (f->source==NULL) f->source=p;
198 f->lineDefined=LoadInt(S); 191 f->lineDefined=LoadInt(S);
199 f->nupvalues=LoadInt(S); 192 f->nups=LoadByte(S);
200 f->numparams=LoadByte(S); 193 f->numparams=LoadByte(S);
201 f->is_vararg=LoadByte(S); 194 f->is_vararg=LoadByte(S);
202 f->maxstacksize=LoadByte(S); 195 f->maxstacksize=LoadByte(S);
diff --git a/lvm.c b/lvm.c
index 5d4b0445..31e7b083 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.273 2002/12/11 12:34:22 roberto Exp roberto $ 2** $Id: lvm.c,v 1.274 2003/01/27 15:12:52 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -754,7 +754,7 @@ StkId luaV_execute (lua_State *L) {
754 Closure *ncl; 754 Closure *ncl;
755 int nup, j; 755 int nup, j;
756 p = cl->p->p[GETARG_Bx(i)]; 756 p = cl->p->p[GETARG_Bx(i)];
757 nup = p->nupvalues; 757 nup = p->nups;
758 ncl = luaF_newLclosure(L, nup, &cl->g); 758 ncl = luaF_newLclosure(L, nup, &cl->g);
759 ncl->l.p = p; 759 ncl->l.p = p;
760 for (j=0; j<nup; j++, pc++) { 760 for (j=0; j<nup; j++, pc++) {