aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldebug.c13
-rw-r--r--lfunc.c15
-rw-r--r--lfunc.h3
-rw-r--r--lgc.c64
-rw-r--r--lobject.h12
-rw-r--r--lstate.h7
-rw-r--r--ltests.c41
7 files changed, 88 insertions, 67 deletions
diff --git a/ldebug.c b/ldebug.c
index e40071e9..431acc1f 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.87 2011/10/07 20:45:19 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.88 2011/11/30 12:43:51 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*/
@@ -30,6 +30,9 @@
30 30
31 31
32 32
33#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_TCCL)
34
35
33static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); 36static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name);
34 37
35 38
@@ -173,7 +176,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
173 176
174 177
175static void funcinfo (lua_Debug *ar, Closure *cl) { 178static void funcinfo (lua_Debug *ar, Closure *cl) {
176 if (cl == NULL || cl->c.isC) { 179 if (noLuaClosure(cl)) {
177 ar->source = "=[C]"; 180 ar->source = "=[C]";
178 ar->linedefined = -1; 181 ar->linedefined = -1;
179 ar->lastlinedefined = -1; 182 ar->lastlinedefined = -1;
@@ -191,7 +194,7 @@ static void funcinfo (lua_Debug *ar, Closure *cl) {
191 194
192 195
193static void collectvalidlines (lua_State *L, Closure *f) { 196static void collectvalidlines (lua_State *L, Closure *f) {
194 if (f == NULL || f->c.isC) { 197 if (noLuaClosure(f)) {
195 setnilvalue(L->top); 198 setnilvalue(L->top);
196 incr_top(L); 199 incr_top(L);
197 } 200 }
@@ -210,7 +213,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
210 213
211 214
212static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, 215static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
213 Closure *f, CallInfo *ci) { 216 Closure *f, CallInfo *ci) {
214 int status = 1; 217 int status = 1;
215 for (; *what; what++) { 218 for (; *what; what++) {
216 switch (*what) { 219 switch (*what) {
@@ -224,7 +227,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
224 } 227 }
225 case 'u': { 228 case 'u': {
226 ar->nups = (f == NULL) ? 0 : f->c.nupvalues; 229 ar->nups = (f == NULL) ? 0 : f->c.nupvalues;
227 if (f == NULL || f->c.isC) { 230 if (noLuaClosure(f)) {
228 ar->isvararg = 1; 231 ar->isvararg = 1;
229 ar->nparams = 0; 232 ar->nparams = 0;
230 } 233 }
diff --git a/lfunc.c b/lfunc.c
index 6e809ca0..8b8f05c1 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 2.26 2010/06/10 21:27:09 roberto Exp roberto $ 2** $Id: lfunc.c,v 2.27 2010/06/30 14:11:17 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*/
@@ -21,8 +21,7 @@
21 21
22 22
23Closure *luaF_newCclosure (lua_State *L, int n) { 23Closure *luaF_newCclosure (lua_State *L, int n) {
24 Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeCclosure(n), NULL, 0)->cl; 24 Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
25 c->c.isC = 1;
26 c->c.nupvalues = cast_byte(n); 25 c->c.nupvalues = cast_byte(n);
27 return c; 26 return c;
28} 27}
@@ -30,8 +29,7 @@ Closure *luaF_newCclosure (lua_State *L, int n) {
30 29
31Closure *luaF_newLclosure (lua_State *L, Proto *p) { 30Closure *luaF_newLclosure (lua_State *L, Proto *p) {
32 int n = p->sizeupvalues; 31 int n = p->sizeupvalues;
33 Closure *c = &luaC_newobj(L, LUA_TFUNCTION, sizeLclosure(n), NULL, 0)->cl; 32 Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
34 c->l.isC = 0;
35 c->l.p = p; 33 c->l.p = p;
36 c->l.nupvalues = cast_byte(n); 34 c->l.nupvalues = cast_byte(n);
37 while (n--) c->l.upvals[n] = NULL; 35 while (n--) c->l.upvals[n] = NULL;
@@ -146,13 +144,6 @@ void luaF_freeproto (lua_State *L, Proto *f) {
146} 144}
147 145
148 146
149void luaF_freeclosure (lua_State *L, Closure *c) {
150 int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
151 sizeLclosure(c->l.nupvalues);
152 luaM_freemem(L, c, size);
153}
154
155
156/* 147/*
157** Look for n-th local variable at line `line' in function `func'. 148** Look for n-th local variable at line `line' in function `func'.
158** Returns NULL if not found. 149** Returns NULL if not found.
diff --git a/lfunc.h b/lfunc.h
index 315ffe1d..f582130e 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.h,v 2.5 2010/03/26 20:58:11 roberto Exp roberto $ 2** $Id: lfunc.h,v 2.6 2010/06/04 13:06:15 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*/
@@ -25,7 +25,6 @@ LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
25LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 25LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
26LUAI_FUNC void luaF_close (lua_State *L, StkId level); 26LUAI_FUNC void luaF_close (lua_State *L, StkId level);
27LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 27LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
28LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
29LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 28LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
30LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 29LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
31 int pc); 30 int pc);
diff --git a/lgc.c b/lgc.c
index 348d3598..18b063c5 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.115 2011/11/28 17:25:48 roberto Exp roberto $ 2** $Id: lgc.c,v 2.116 2011/12/02 13:18:41 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*/
@@ -217,7 +217,8 @@ void luaC_checkupvalcolor (global_State *g, UpVal *uv) {
217GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list, 217GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
218 int offset) { 218 int offset) {
219 global_State *g = G(L); 219 global_State *g = G(L);
220 GCObject *o = obj2gco(cast(char *, luaM_newobject(L, tt, sz)) + offset); 220 char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
221 GCObject *o = obj2gco(raw + offset);
221 if (list == NULL) 222 if (list == NULL)
222 list = &g->allgc; /* standard list for collectable objects */ 223 list = &g->allgc; /* standard list for collectable objects */
223 gch(o)->marked = luaC_white(g); 224 gch(o)->marked = luaC_white(g);
@@ -266,8 +267,13 @@ static void reallymarkobject (global_State *g, GCObject *o) {
266 gray2black(o); /* make it black */ 267 gray2black(o); /* make it black */
267 return; 268 return;
268 } 269 }
269 case LUA_TFUNCTION: { 270 case LUA_TLCL: {
270 gco2cl(o)->c.gclist = g->gray; 271 gco2lcl(o)->gclist = g->gray;
272 g->gray = o;
273 break;
274 }
275 case LUA_TCCL: {
276 gco2ccl(o)->gclist = g->gray;
271 g->gray = o; 277 g->gray = o;
272 break; 278 break;
273 } 279 }
@@ -470,20 +476,20 @@ static int traverseproto (global_State *g, Proto *f) {
470} 476}
471 477
472 478
473static int traverseclosure (global_State *g, Closure *cl) { 479static int traverseCclosure (global_State *g, CClosure *cl) {
474 if (cl->c.isC) { 480 int i;
475 int i; 481 for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
476 for (i=0; i<cl->c.nupvalues; i++) /* mark its upvalues */ 482 markvalue(g, &cl->upvalue[i]);
477 markvalue(g, &cl->c.upvalue[i]); 483 return TRAVCOST + cl->nupvalues;
478 } 484}
479 else { 485
480 int i; 486static int traverseLclosure (global_State *g, LClosure *cl) {
481 lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); 487 int i;
482 markobject(g, cl->l.p); /* mark its prototype */ 488 assert(cl->nupvalues == cl->p->sizeupvalues);
483 for (i=0; i<cl->l.nupvalues; i++) /* mark its upvalues */ 489 markobject(g, cl->p); /* mark its prototype */
484 markobject(g, cl->l.upvals[i]); 490 for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
485 } 491 markobject(g, cl->upvals[i]);
486 return TRAVCOST + cl->c.nupvalues; 492 return TRAVCOST + cl->nupvalues;
487} 493}
488 494
489 495
@@ -517,10 +523,15 @@ static int propagatemark (global_State *g) {
517 g->gray = h->gclist; 523 g->gray = h->gclist;
518 return traversetable(g, h); 524 return traversetable(g, h);
519 } 525 }
520 case LUA_TFUNCTION: { 526 case LUA_TLCL: {
521 Closure *cl = gco2cl(o); 527 LClosure *cl = gco2lcl(o);
522 g->gray = cl->c.gclist; 528 g->gray = cl->gclist;
523 return traverseclosure(g, cl); 529 return traverseLclosure(g, cl);
530 }
531 case LUA_TCCL: {
532 CClosure *cl = gco2ccl(o);
533 g->gray = cl->gclist;
534 return traverseCclosure(g, cl);
524 } 535 }
525 case LUA_TTHREAD: { 536 case LUA_TTHREAD: {
526 lua_State *th = gco2th(o); 537 lua_State *th = gco2th(o);
@@ -640,7 +651,14 @@ static void clearvalues (GCObject *l, GCObject *f) {
640static void freeobj (lua_State *L, GCObject *o) { 651static void freeobj (lua_State *L, GCObject *o) {
641 switch (gch(o)->tt) { 652 switch (gch(o)->tt) {
642 case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; 653 case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
643 case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break; 654 case LUA_TLCL: {
655 luaM_freemem(L, o, sizeLclosure(gco2lcl(o)->nupvalues));
656 break;
657 }
658 case LUA_TCCL: {
659 luaM_freemem(L, o, sizeCclosure(gco2ccl(o)->nupvalues));
660 break;
661 }
644 case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break; 662 case LUA_TUPVAL: luaF_freeupval(L, gco2uv(o)); break;
645 case LUA_TTABLE: luaH_free(L, gco2t(o)); break; 663 case LUA_TTABLE: luaH_free(L, gco2t(o)); break;
646 case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break; 664 case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break;
diff --git a/lobject.h b/lobject.h
index 1d431d36..bb700fc7 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.63 2011/10/17 14:46:13 roberto Exp roberto $ 2** $Id: lobject.h,v 2.64 2011/10/31 17:48:22 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*/
@@ -109,12 +109,14 @@ typedef struct lua_TValue TValue;
109/* raw type tag of a TValue */ 109/* raw type tag of a TValue */
110#define rttype(o) ((o)->tt_) 110#define rttype(o) ((o)->tt_)
111 111
112/* tag with no variants (bits 0-3) */
113#define novariant(x) ((x) & 0x0F)
114
112/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ 115/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
113#define ttype(o) (rttype(o) & 0x3F) 116#define ttype(o) (rttype(o) & 0x3F)
114 117
115
116/* type tag of a TValue with no variants (bits 0-3) */ 118/* type tag of a TValue with no variants (bits 0-3) */
117#define ttypenv(o) (rttype(o) & 0x0F) 119#define ttypenv(o) (novariant(rttype(o)))
118 120
119 121
120/* Macros to test type */ 122/* Macros to test type */
@@ -161,7 +163,7 @@ typedef struct lua_TValue TValue;
161 163
162 164
163/* Macros for internal tests */ 165/* Macros for internal tests */
164#define righttt(obj) (ttypenv(obj) == gcvalue(obj)->gch.tt) 166#define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt)
165 167
166#define checkliveness(g,obj) \ 168#define checkliveness(g,obj) \
167 lua_longassert(!iscollectable(obj) || \ 169 lua_longassert(!iscollectable(obj) || \
@@ -501,7 +503,7 @@ typedef struct UpVal {
501*/ 503*/
502 504
503#define ClosureHeader \ 505#define ClosureHeader \
504 CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist 506 CommonHeader; lu_byte nupvalues; GCObject *gclist
505 507
506typedef struct CClosure { 508typedef struct CClosure {
507 ClosureHeader; 509 ClosureHeader;
diff --git a/lstate.h b/lstate.h
index b1538239..cff8e202 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.73 2011/08/23 17:24:34 roberto Exp roberto $ 2** $Id: lstate.h,v 2.74 2011/09/30 12:45:07 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -197,7 +197,10 @@ union GCObject {
197#define gco2ts(o) (&rawgco2ts(o)->tsv) 197#define gco2ts(o) (&rawgco2ts(o)->tsv)
198#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) 198#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
199#define gco2u(o) (&rawgco2u(o)->uv) 199#define gco2u(o) (&rawgco2u(o)->uv)
200#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) 200#define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l))
201#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
202#define gco2cl(o) \
203 check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl))
201#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) 204#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
202#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) 205#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
203#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 206#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
diff --git a/ltests.c b/ltests.c
index 33266f38..7b4c0e17 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.123 2011/09/24 21:11:29 roberto Exp roberto $ 2** $Id: ltests.c,v 2.124 2011/11/09 19:08:07 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -267,22 +267,23 @@ static void checkproto (global_State *g, Proto *f) {
267 267
268 268
269 269
270static void checkclosure (global_State *g, Closure *cl) { 270static void checkCclosure (global_State *g, CClosure *cl) {
271 GCObject *clgc = obj2gco(cl); 271 GCObject *clgc = obj2gco(cl);
272 if (cl->c.isC) { 272 int i;
273 int i; 273 for (i = 0; i < cl->nupvalues; i++)
274 for (i=0; i<cl->c.nupvalues; i++) 274 checkvalref(g, clgc, &cl->upvalue[i]);
275 checkvalref(g, clgc, &cl->c.upvalue[i]); 275}
276 } 276
277 else { 277
278 int i; 278static void checkLclosure (global_State *g, LClosure *cl) {
279 lua_assert(cl->l.nupvalues == cl->l.p->sizeupvalues); 279 GCObject *clgc = obj2gco(cl);
280 checkobjref(g, clgc, cl->l.p); 280 int i;
281 for (i=0; i<cl->l.nupvalues; i++) { 281 lua_assert(cl->nupvalues == cl->p->sizeupvalues);
282 if (cl->l.upvals[i]) { 282 checkobjref(g, clgc, cl->p);
283 lua_assert(cl->l.upvals[i]->tt == LUA_TUPVAL); 283 for (i=0; i<cl->nupvalues; i++) {
284 checkobjref(g, clgc, cl->l.upvals[i]); 284 if (cl->upvals[i]) {
285 } 285 lua_assert(cl->upvals[i]->tt == LUA_TUPVAL);
286 checkobjref(g, clgc, cl->upvals[i]);
286 } 287 }
287 } 288 }
288} 289}
@@ -347,8 +348,12 @@ static void checkobject (global_State *g, GCObject *o) {
347 checkstack(g, gco2th(o)); 348 checkstack(g, gco2th(o));
348 break; 349 break;
349 } 350 }
350 case LUA_TFUNCTION: { 351 case LUA_TLCL: {
351 checkclosure(g, gco2cl(o)); 352 checkLclosure(g, gco2lcl(o));
353 break;
354 }
355 case LUA_TCCL: {
356 checkCclosure(g, gco2ccl(o));
352 break; 357 break;
353 } 358 }
354 case LUA_TPROTO: { 359 case LUA_TPROTO: {