summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c111
-rw-r--r--lapi.h4
-rw-r--r--lcode.c24
-rw-r--r--ldebug.c20
-rw-r--r--ldebug.h8
-rw-r--r--ldo.c35
-rw-r--r--ldo.h6
-rw-r--r--ldump.c6
-rw-r--r--lfunc.c20
-rw-r--r--lfunc.h8
-rw-r--r--lgc.c104
-rw-r--r--lgc.h10
-rw-r--r--llex.c4
-rw-r--r--lobject.c10
-rw-r--r--lobject.h103
-rw-r--r--lparser.c8
-rw-r--r--lstate.c19
-rw-r--r--lstate.h26
-rw-r--r--lstring.c10
-rw-r--r--ltable.c72
-rw-r--r--ltable.h16
-rw-r--r--ltests.c8
-rw-r--r--ltests.h3
-rw-r--r--ltm.c10
-rw-r--r--ltm.h6
-rw-r--r--lundump.c24
-rw-r--r--lvm.c158
-rw-r--r--lvm.h12
-rw-r--r--makefile52
29 files changed, 456 insertions, 441 deletions
diff --git a/lapi.c b/lapi.c
index d342fc94..b5bb81af 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.250 2003/12/01 18:22:56 roberto Exp roberto $ 2** $Id: lapi.c,v 1.251 2003/12/09 16:56:11 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*/
@@ -41,7 +41,7 @@ const char lua_ident[] =
41 41
42 42
43#ifndef api_check 43#ifndef api_check
44#define api_check(L, o) /*{ assert(o); }*/ 44#define api_check(L, o) lua_assert(o)
45#endif 45#endif
46 46
47#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base)) 47#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
@@ -52,11 +52,11 @@ const char lua_ident[] =
52 52
53 53
54 54
55static TObject *luaA_index (lua_State *L, int idx) { 55static TValue *luaA_index (lua_State *L, int idx) {
56 if (idx > 0) { 56 if (idx > 0) {
57 TObject *o = L->base + (idx - 1); 57 TValue *o = L->base + (idx - 1);
58 api_check(L, idx <= L->stack_last - L->base); 58 api_check(L, idx <= L->stack_last - L->base);
59 if (o >= L->top) return cast(TObject *, &luaO_nilobject); 59 if (o >= L->top) return cast(TValue *, &luaO_nilobject);
60 else return o; 60 else return o;
61 } 61 }
62 else if (idx > LUA_REGISTRYINDEX) { 62 else if (idx > LUA_REGISTRYINDEX) {
@@ -67,19 +67,19 @@ static TObject *luaA_index (lua_State *L, int idx) {
67 case LUA_REGISTRYINDEX: return registry(L); 67 case LUA_REGISTRYINDEX: return registry(L);
68 case LUA_GLOBALSINDEX: return gt(L); 68 case LUA_GLOBALSINDEX: return gt(L);
69 default: { 69 default: {
70 TObject *func = (L->base - 1); 70 TValue *func = (L->base - 1);
71 idx = LUA_GLOBALSINDEX - idx; 71 idx = LUA_GLOBALSINDEX - idx;
72 lua_assert(iscfunction(func)); 72 lua_assert(iscfunction(func));
73 return (idx <= clvalue(func)->c.nupvalues) 73 return (idx <= clvalue(func)->c.nupvalues)
74 ? &clvalue(func)->c.upvalue[idx-1] 74 ? &clvalue(func)->c.upvalue[idx-1]
75 : cast(TObject *, &luaO_nilobject); 75 : cast(TValue *, &luaO_nilobject);
76 } 76 }
77 } 77 }
78} 78}
79 79
80 80
81void luaA_pushobject (lua_State *L, const TObject *o) { 81void luaA_pushobject (lua_State *L, const TValue *o) {
82 setobj2s(L->top, o); 82 setobj2s(L, L->top, o);
83 incr_top(L); 83 incr_top(L);
84} 84}
85 85
@@ -107,7 +107,7 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
107 api_checknelems(from, n); 107 api_checknelems(from, n);
108 from->top -= n; 108 from->top -= n;
109 for (i = 0; i < n; i++) { 109 for (i = 0; i < n; i++) {
110 setobj2s(to->top, from->top + i); 110 setobj2s(to, to->top, from->top + i);
111 api_incr_top(to); 111 api_incr_top(to);
112 } 112 }
113 lua_unlock(to); 113 lua_unlock(to);
@@ -129,7 +129,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
129 lua_lock(L); 129 lua_lock(L);
130 luaC_checkGC(L); 130 luaC_checkGC(L);
131 L1 = luaE_newthread(L); 131 L1 = luaE_newthread(L);
132 setthvalue(L->top, L1); 132 setthvalue(L, L->top, L1);
133 api_incr_top(L); 133 api_incr_top(L);
134 lua_unlock(L); 134 lua_unlock(L);
135 lua_userstateopen(L1); 135 lua_userstateopen(L1);
@@ -169,7 +169,7 @@ LUA_API void lua_remove (lua_State *L, int idx) {
169 lua_lock(L); 169 lua_lock(L);
170 p = luaA_index(L, idx); 170 p = luaA_index(L, idx);
171 api_checkvalidindex(L, p); 171 api_checkvalidindex(L, p);
172 while (++p < L->top) setobjs2s(p-1, p); 172 while (++p < L->top) setobjs2s(L, p-1, p);
173 L->top--; 173 L->top--;
174 lua_unlock(L); 174 lua_unlock(L);
175} 175}
@@ -181,8 +181,8 @@ LUA_API void lua_insert (lua_State *L, int idx) {
181 lua_lock(L); 181 lua_lock(L);
182 p = luaA_index(L, idx); 182 p = luaA_index(L, idx);
183 api_checkvalidindex(L, p); 183 api_checkvalidindex(L, p);
184 for (q = L->top; q>p; q--) setobjs2s(q, q-1); 184 for (q = L->top; q>p; q--) setobjs2s(L, q, q-1);
185 setobjs2s(p, L->top); 185 setobjs2s(L, p, L->top);
186 lua_unlock(L); 186 lua_unlock(L);
187} 187}
188 188
@@ -193,7 +193,7 @@ LUA_API void lua_replace (lua_State *L, int idx) {
193 api_checknelems(L, 1); 193 api_checknelems(L, 1);
194 o = luaA_index(L, idx); 194 o = luaA_index(L, idx);
195 api_checkvalidindex(L, o); 195 api_checkvalidindex(L, o);
196 setobj(o, L->top - 1); /* write barrier???? */ 196 setobj(L, o, L->top - 1); /* write barrier???? */
197 L->top--; 197 L->top--;
198 lua_unlock(L); 198 lua_unlock(L);
199} 199}
@@ -201,7 +201,7 @@ LUA_API void lua_replace (lua_State *L, int idx) {
201 201
202LUA_API void lua_pushvalue (lua_State *L, int idx) { 202LUA_API void lua_pushvalue (lua_State *L, int idx) {
203 lua_lock(L); 203 lua_lock(L);
204 setobj2s(L->top, luaA_index(L, idx)); 204 setobj2s(L, L->top, luaA_index(L, idx));
205 api_incr_top(L); 205 api_incr_top(L);
206 lua_unlock(L); 206 lua_unlock(L);
207} 207}
@@ -232,8 +232,8 @@ LUA_API int lua_iscfunction (lua_State *L, int idx) {
232 232
233 233
234LUA_API int lua_isnumber (lua_State *L, int idx) { 234LUA_API int lua_isnumber (lua_State *L, int idx) {
235 TObject n; 235 TValue n;
236 const TObject *o = luaA_index(L, idx); 236 const TValue *o = luaA_index(L, idx);
237 return tonumber(o, &n); 237 return tonumber(o, &n);
238} 238}
239 239
@@ -245,7 +245,7 @@ LUA_API int lua_isstring (lua_State *L, int idx) {
245 245
246 246
247LUA_API int lua_isuserdata (lua_State *L, int idx) { 247LUA_API int lua_isuserdata (lua_State *L, int idx) {
248 const TObject *o = luaA_index(L, idx); 248 const TValue *o = luaA_index(L, idx);
249 return (ttisuserdata(o) || ttislightuserdata(o)); 249 return (ttisuserdata(o) || ttislightuserdata(o));
250} 250}
251 251
@@ -286,8 +286,8 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
286 286
287 287
288LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { 288LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
289 TObject n; 289 TValue n;
290 const TObject *o = luaA_index(L, idx); 290 const TValue *o = luaA_index(L, idx);
291 if (tonumber(o, &n)) 291 if (tonumber(o, &n))
292 return nvalue(o); 292 return nvalue(o);
293 else 293 else
@@ -296,8 +296,8 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
296 296
297 297
298LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) { 298LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
299 TObject n; 299 TValue n;
300 const TObject *o = luaA_index(L, idx); 300 const TValue *o = luaA_index(L, idx);
301 if (tonumber(o, &n)) { 301 if (tonumber(o, &n)) {
302 lua_Integer res; 302 lua_Integer res;
303 lua_number2integer(res, nvalue(o)); 303 lua_number2integer(res, nvalue(o));
@@ -309,7 +309,7 @@ LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
309 309
310 310
311LUA_API int lua_toboolean (lua_State *L, int idx) { 311LUA_API int lua_toboolean (lua_State *L, int idx) {
312 const TObject *o = luaA_index(L, idx); 312 const TValue *o = luaA_index(L, idx);
313 return !l_isfalse(o); 313 return !l_isfalse(o);
314} 314}
315 315
@@ -332,11 +332,11 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) {
332LUA_API size_t lua_strlen (lua_State *L, int idx) { 332LUA_API size_t lua_strlen (lua_State *L, int idx) {
333 StkId o = luaA_index(L, idx); 333 StkId o = luaA_index(L, idx);
334 if (ttisstring(o)) 334 if (ttisstring(o))
335 return tsvalue(o)->tsv.len; 335 return tsvalue(o)->len;
336 else { 336 else {
337 size_t l; 337 size_t l;
338 lua_lock(L); /* `luaV_tostring' may create a new string */ 338 lua_lock(L); /* `luaV_tostring' may create a new string */
339 l = (luaV_tostring(L, o) ? tsvalue(o)->tsv.len : 0); 339 l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0);
340 lua_unlock(L); 340 lua_unlock(L);
341 return l; 341 return l;
342 } 342 }
@@ -352,7 +352,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
352LUA_API void *lua_touserdata (lua_State *L, int idx) { 352LUA_API void *lua_touserdata (lua_State *L, int idx) {
353 StkId o = luaA_index(L, idx); 353 StkId o = luaA_index(L, idx);
354 switch (ttype(o)) { 354 switch (ttype(o)) {
355 case LUA_TUSERDATA: return (uvalue(o) + 1); 355 case LUA_TUSERDATA: return (rawuvalue(o) + 1);
356 case LUA_TLIGHTUSERDATA: return pvalue(o); 356 case LUA_TLIGHTUSERDATA: return pvalue(o);
357 default: return NULL; 357 default: return NULL;
358 } 358 }
@@ -412,7 +412,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
412LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { 412LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
413 lua_lock(L); 413 lua_lock(L);
414 luaC_checkGC(L); 414 luaC_checkGC(L);
415 setsvalue2s(L->top, luaS_newlstr(L, s, len)); 415 setsvalue2s(L, L->top, luaS_newlstr(L, s, len));
416 api_incr_top(L); 416 api_incr_top(L);
417 lua_unlock(L); 417 lua_unlock(L);
418} 418}
@@ -459,8 +459,9 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
459 cl->c.f = fn; 459 cl->c.f = fn;
460 L->top -= n; 460 L->top -= n;
461 while (n--) 461 while (n--)
462 setobj2n(&cl->c.upvalue[n], L->top+n); 462 setobj2n(L, &cl->c.upvalue[n], L->top+n);
463 setclvalue(L->top, cl); 463 setclvalue(L, L->top, cl);
464 lua_assert(iswhite(obj2gco(cl)));
464 api_incr_top(L); 465 api_incr_top(L);
465 lua_unlock(L); 466 lua_unlock(L);
466} 467}
@@ -500,11 +501,11 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
500 501
501LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { 502LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
502 StkId t; 503 StkId t;
503 TObject key; 504 TValue key;
504 lua_lock(L); 505 lua_lock(L);
505 t = luaA_index(L, idx); 506 t = luaA_index(L, idx);
506 api_checkvalidindex(L, t); 507 api_checkvalidindex(L, t);
507 setsvalue(&key, luaS_new(L, k)); 508 setsvalue(L, &key, luaS_new(L, k));
508 luaV_gettable(L, t, &key, L->top); 509 luaV_gettable(L, t, &key, L->top);
509 api_incr_top(L); 510 api_incr_top(L);
510 lua_unlock(L); 511 lua_unlock(L);
@@ -516,7 +517,7 @@ LUA_API void lua_rawget (lua_State *L, int idx) {
516 lua_lock(L); 517 lua_lock(L);
517 t = luaA_index(L, idx); 518 t = luaA_index(L, idx);
518 api_check(L, ttistable(t)); 519 api_check(L, ttistable(t));
519 setobj2s(L->top - 1, luaH_get(hvalue(t), L->top - 1)); 520 setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
520 lua_unlock(L); 521 lua_unlock(L);
521} 522}
522 523
@@ -526,7 +527,7 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
526 lua_lock(L); 527 lua_lock(L);
527 o = luaA_index(L, idx); 528 o = luaA_index(L, idx);
528 api_check(L, ttistable(o)); 529 api_check(L, ttistable(o));
529 setobj2s(L->top, luaH_getnum(hvalue(o), n)); 530 setobj2s(L, L->top, luaH_getnum(hvalue(o), n));
530 api_incr_top(L); 531 api_incr_top(L);
531 lua_unlock(L); 532 lua_unlock(L);
532} 533}
@@ -535,14 +536,14 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
535LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { 536LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
536 lua_lock(L); 537 lua_lock(L);
537 luaC_checkGC(L); 538 luaC_checkGC(L);
538 sethvalue(L->top, luaH_new(L, narray, luaO_log2(nrec) + 1)); 539 sethvalue(L, L->top, luaH_new(L, narray, luaO_log2(nrec) + 1));
539 api_incr_top(L); 540 api_incr_top(L);
540 lua_unlock(L); 541 lua_unlock(L);
541} 542}
542 543
543 544
544LUA_API int lua_getmetatable (lua_State *L, int objindex) { 545LUA_API int lua_getmetatable (lua_State *L, int objindex) {
545 const TObject *obj; 546 const TValue *obj;
546 Table *mt = NULL; 547 Table *mt = NULL;
547 int res; 548 int res;
548 lua_lock(L); 549 lua_lock(L);
@@ -552,13 +553,13 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
552 mt = hvalue(obj)->metatable; 553 mt = hvalue(obj)->metatable;
553 break; 554 break;
554 case LUA_TUSERDATA: 555 case LUA_TUSERDATA:
555 mt = uvalue(obj)->uv.metatable; 556 mt = uvalue(obj)->metatable;
556 break; 557 break;
557 } 558 }
558 if (mt == NULL) 559 if (mt == NULL)
559 res = 0; 560 res = 0;
560 else { 561 else {
561 sethvalue(L->top, mt); 562 sethvalue(L, L->top, mt);
562 api_incr_top(L); 563 api_incr_top(L);
563 res = 1; 564 res = 1;
564 } 565 }
@@ -572,7 +573,7 @@ LUA_API void lua_getfenv (lua_State *L, int idx) {
572 lua_lock(L); 573 lua_lock(L);
573 o = luaA_index(L, idx); 574 o = luaA_index(L, idx);
574 api_checkvalidindex(L, o); 575 api_checkvalidindex(L, o);
575 setobj2s(L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L)); 576 setobj2s(L, L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L));
576 api_incr_top(L); 577 api_incr_top(L);
577 lua_unlock(L); 578 lua_unlock(L);
578} 579}
@@ -597,12 +598,12 @@ LUA_API void lua_settable (lua_State *L, int idx) {
597 598
598LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { 599LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
599 StkId t; 600 StkId t;
600 TObject key; 601 TValue key;
601 lua_lock(L); 602 lua_lock(L);
602 api_checknelems(L, 1); 603 api_checknelems(L, 1);
603 t = luaA_index(L, idx); 604 t = luaA_index(L, idx);
604 api_checkvalidindex(L, t); 605 api_checkvalidindex(L, t);
605 setsvalue(&key, luaS_new(L, k)); 606 setsvalue(L, &key, luaS_new(L, k));
606 luaV_settable(L, t, &key, L->top - 1); 607 luaV_settable(L, t, &key, L->top - 1);
607 L->top--; /* pop value */ 608 L->top--; /* pop value */
608 lua_unlock(L); 609 lua_unlock(L);
@@ -615,7 +616,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
615 api_checknelems(L, 2); 616 api_checknelems(L, 2);
616 t = luaA_index(L, idx); 617 t = luaA_index(L, idx);
617 api_check(L, ttistable(t)); 618 api_check(L, ttistable(t));
618 setobj2t(luaH_set(L, hvalue(t), L->top-2), L->top-1); 619 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
619 luaC_barrier(L, hvalue(t), L->top-1); 620 luaC_barrier(L, hvalue(t), L->top-1);
620 L->top -= 2; 621 L->top -= 2;
621 lua_unlock(L); 622 lua_unlock(L);
@@ -628,7 +629,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
628 api_checknelems(L, 1); 629 api_checknelems(L, 1);
629 o = luaA_index(L, idx); 630 o = luaA_index(L, idx);
630 api_check(L, ttistable(o)); 631 api_check(L, ttistable(o));
631 setobj2t(luaH_setnum(L, hvalue(o), n), L->top-1); 632 setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
632 luaC_barrier(L, hvalue(o), L->top-1); 633 luaC_barrier(L, hvalue(o), L->top-1);
633 L->top--; 634 L->top--;
634 lua_unlock(L); 635 lua_unlock(L);
@@ -636,7 +637,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
636 637
637 638
638LUA_API int lua_setmetatable (lua_State *L, int objindex) { 639LUA_API int lua_setmetatable (lua_State *L, int objindex) {
639 TObject *obj; 640 TValue *obj;
640 Table *mt; 641 Table *mt;
641 int res = 1; 642 int res = 1;
642 lua_lock(L); 643 lua_lock(L);
@@ -657,9 +658,9 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
657 break; 658 break;
658 } 659 }
659 case LUA_TUSERDATA: { 660 case LUA_TUSERDATA: {
660 uvalue(obj)->uv.metatable = mt; 661 uvalue(obj)->metatable = mt;
661 if (mt) 662 if (mt)
662 luaC_objbarrier(L, uvalue(obj), mt); 663 luaC_objbarrier(L, rawuvalue(obj), mt);
663 break; 664 break;
664 } 665 }
665 default: { 666 default: {
@@ -756,7 +757,7 @@ static void f_Ccall (lua_State *L, void *ud) {
756 Closure *cl; 757 Closure *cl;
757 cl = luaF_newCclosure(L, 0); 758 cl = luaF_newCclosure(L, 0);
758 cl->c.f = c->func; 759 cl->c.f = c->func;
759 setclvalue(L->top, cl); /* push function */ 760 setclvalue(L, L->top, cl); /* push function */
760 incr_top(L); 761 incr_top(L);
761 setpvalue(L->top, c->ud); /* push only argument */ 762 setpvalue(L->top, c->ud); /* push only argument */
762 incr_top(L); 763 incr_top(L);
@@ -791,7 +792,7 @@ LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data,
791 792
792LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) { 793LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
793 int status; 794 int status;
794 TObject *o; 795 TValue *o;
795 lua_lock(L); 796 lua_lock(L);
796 api_checknelems(L, 1); 797 api_checknelems(L, 1);
797 o = L->top - 1; 798 o = L->top - 1;
@@ -885,7 +886,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
885 L->top -= (n-1); 886 L->top -= (n-1);
886 } 887 }
887 else if (n == 0) { /* push empty string */ 888 else if (n == 0) { /* push empty string */
888 setsvalue2s(L->top, luaS_newlstr(L, NULL, 0)); 889 setsvalue2s(L, L->top, luaS_newlstr(L, NULL, 0));
889 api_incr_top(L); 890 api_incr_top(L);
890 } 891 }
891 /* else n == 1; nothing to do */ 892 /* else n == 1; nothing to do */
@@ -904,7 +905,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
904 lua_lock(L); 905 lua_lock(L);
905 luaC_checkGC(L); 906 luaC_checkGC(L);
906 u = luaS_newudata(L, size); 907 u = luaS_newudata(L, size);
907 setuvalue(L->top, u); 908 setuvalue(L, L->top, u);
908 api_incr_top(L); 909 api_incr_top(L);
909 lua_unlock(L); 910 lua_unlock(L);
910 return u + 1; 911 return u + 1;
@@ -913,7 +914,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
913 914
914 915
915 916
916static const char *aux_upvalue (lua_State *L, StkId fi, int n, TObject **val) { 917static const char *aux_upvalue (lua_State *L, StkId fi, int n, TValue **val) {
917 Closure *f; 918 Closure *f;
918 if (!ttisfunction(fi)) return NULL; 919 if (!ttisfunction(fi)) return NULL;
919 f = clvalue(fi); 920 f = clvalue(fi);
@@ -933,11 +934,11 @@ static const char *aux_upvalue (lua_State *L, StkId fi, int n, TObject **val) {
933 934
934LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { 935LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
935 const char *name; 936 const char *name;
936 TObject *val; 937 TValue *val;
937 lua_lock(L); 938 lua_lock(L);
938 name = aux_upvalue(L, luaA_index(L, funcindex), n, &val); 939 name = aux_upvalue(L, luaA_index(L, funcindex), n, &val);
939 if (name) { 940 if (name) {
940 setobj2s(L->top, val); 941 setobj2s(L, L->top, val);
941 api_incr_top(L); 942 api_incr_top(L);
942 } 943 }
943 lua_unlock(L); 944 lua_unlock(L);
@@ -947,7 +948,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
947 948
948LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { 949LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
949 const char *name; 950 const char *name;
950 TObject *val; 951 TValue *val;
951 StkId fi; 952 StkId fi;
952 lua_lock(L); 953 lua_lock(L);
953 fi = luaA_index(L, funcindex); 954 fi = luaA_index(L, funcindex);
@@ -955,7 +956,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
955 name = aux_upvalue(L, fi, n, &val); 956 name = aux_upvalue(L, fi, n, &val);
956 if (name) { 957 if (name) {
957 L->top--; 958 L->top--;
958 setobj(val, L->top); 959 setobj(L, val, L->top);
959 luaC_barrier(L, clvalue(fi), L->top); 960 luaC_barrier(L, clvalue(fi), L->top);
960 } 961 }
961 lua_unlock(L); 962 lua_unlock(L);
diff --git a/lapi.h b/lapi.h
index 61f18b88..618448a6 100644
--- a/lapi.h
+++ b/lapi.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.h,v 1.20 2000/08/31 14:08:27 roberto Exp roberto $ 2** $Id: lapi.h,v 1.21 2002/03/04 21:29:41 roberto Exp roberto $
3** Auxiliary functions from Lua API 3** Auxiliary functions from Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,6 @@
11#include "lobject.h" 11#include "lobject.h"
12 12
13 13
14void luaA_pushobject (lua_State *L, const TObject *o); 14void luaA_pushobject (lua_State *L, const TValue *o);
15 15
16#endif 16#endif
diff --git a/lcode.c b/lcode.c
index af96d4f8..63f48292 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.120 2003/11/19 19:59:18 roberto Exp roberto $ 2** $Id: lcode.c,v 1.121 2003/12/09 16:56:11 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -207,8 +207,9 @@ static void freeexp (FuncState *fs, expdesc *e) {
207} 207}
208 208
209 209
210static int addk (FuncState *fs, TObject *k, TObject *v) { 210static int addk (FuncState *fs, TValue *k, TValue *v) {
211 TObject *idx = luaH_set(fs->L, fs->h, k); 211 lua_State *L = fs->L;
212 TValue *idx = luaH_set(L, fs->h, k);
212 Proto *f = fs->f; 213 Proto *f = fs->f;
213 int oldsize = f->sizek; 214 int oldsize = f->sizek;
214 if (ttisnumber(idx)) { 215 if (ttisnumber(idx)) {
@@ -217,34 +218,35 @@ static int addk (FuncState *fs, TObject *k, TObject *v) {
217 } 218 }
218 else { /* constant not found; create a new entry */ 219 else { /* constant not found; create a new entry */
219 setnvalue(idx, cast(lua_Number, fs->nk)); 220 setnvalue(idx, cast(lua_Number, fs->nk));
220 luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject, 221 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
221 MAXARG_Bx, "constant table overflow"); 222 MAXARG_Bx, "constant table overflow");
222 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); 223 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
223 setobj(&f->k[fs->nk], v); 224 setobj(L, &f->k[fs->nk], v);
224 luaC_barrier(fs->L, f, v); 225 luaC_barrier(L, f, v);
225 return fs->nk++; 226 return fs->nk++;
226 } 227 }
227} 228}
228 229
229 230
230int luaK_stringK (FuncState *fs, TString *s) { 231int luaK_stringK (FuncState *fs, TString *s) {
231 TObject o; 232 TValue o;
232 setsvalue(&o, s); 233 setsvalue(fs->L, &o, s);
233 return addk(fs, &o, &o); 234 return addk(fs, &o, &o);
234} 235}
235 236
236 237
237int luaK_numberK (FuncState *fs, lua_Number r) { 238int luaK_numberK (FuncState *fs, lua_Number r) {
238 TObject o; 239 TValue o;
239 setnvalue(&o, r); 240 setnvalue(&o, r);
240 return addk(fs, &o, &o); 241 return addk(fs, &o, &o);
241} 242}
242 243
243 244
244static int nil_constant (FuncState *fs) { 245static int nil_constant (FuncState *fs) {
245 TObject k, v; 246 TValue k, v;
246 setnilvalue(&v); 247 setnilvalue(&v);
247 sethvalue(&k, fs->h); /* cannot use nil as key; instead use table itself */ 248 /* cannot use nil as key; instead use table itself to represent nil */
249 sethvalue(fs->L, &k, fs->h);
248 return addk(fs, &k, &v); 250 return addk(fs, &k, &v);
249} 251}
250 252
diff --git a/ldebug.c b/ldebug.c
index b4793984..114214d6 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.156 2003/10/02 19:21:09 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.157 2003/10/20 18:42:28 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*/
@@ -136,7 +136,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
136 if (!name || name[0] == '(') /* `(' starts private locals */ 136 if (!name || name[0] == '(') /* `(' starts private locals */
137 name = NULL; 137 name = NULL;
138 else 138 else
139 setobjs2s(ci->base+(n-1), L->top); 139 setobjs2s(L, ci->base+(n-1), L->top);
140 } 140 }
141 lua_unlock(L); 141 lua_unlock(L);
142 return name; 142 return name;
@@ -196,7 +196,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
196 break; 196 break;
197 } 197 }
198 case 'f': { 198 case 'f': {
199 setobj2s(L->top, f); 199 setobj2s(L, L->top, f);
200 break; 200 break;
201 } 201 }
202 default: status = 0; /* invalid option */ 202 default: status = 0; /* invalid option */
@@ -484,7 +484,7 @@ static const char *getfuncname (CallInfo *ci, const char **name) {
484 484
485 485
486/* only ANSI way to check whether a pointer points to an array */ 486/* only ANSI way to check whether a pointer points to an array */
487static int isinstack (CallInfo *ci, const TObject *o) { 487static int isinstack (CallInfo *ci, const TValue *o) {
488 StkId p; 488 StkId p;
489 for (p = ci->base; p < ci->top; p++) 489 for (p = ci->base; p < ci->top; p++)
490 if (o == p) return 1; 490 if (o == p) return 1;
@@ -492,7 +492,7 @@ static int isinstack (CallInfo *ci, const TObject *o) {
492} 492}
493 493
494 494
495void luaG_typeerror (lua_State *L, const TObject *o, const char *op) { 495void luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
496 const char *name = NULL; 496 const char *name = NULL;
497 const char *t = luaT_typenames[ttype(o)]; 497 const char *t = luaT_typenames[ttype(o)];
498 const char *kind = (isinstack(L->ci, o)) ? 498 const char *kind = (isinstack(L->ci, o)) ?
@@ -512,15 +512,15 @@ void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
512} 512}
513 513
514 514
515void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2) { 515void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
516 TObject temp; 516 TValue temp;
517 if (luaV_tonumber(p1, &temp) == NULL) 517 if (luaV_tonumber(p1, &temp) == NULL)
518 p2 = p1; /* first operand is wrong */ 518 p2 = p1; /* first operand is wrong */
519 luaG_typeerror(L, p2, "perform arithmetic on"); 519 luaG_typeerror(L, p2, "perform arithmetic on");
520} 520}
521 521
522 522
523int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { 523int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) {
524 const char *t1 = luaT_typenames[ttype(p1)]; 524 const char *t1 = luaT_typenames[ttype(p1)];
525 const char *t2 = luaT_typenames[ttype(p2)]; 525 const char *t2 = luaT_typenames[ttype(p2)];
526 if (t1[2] == t2[2]) 526 if (t1[2] == t2[2])
@@ -546,8 +546,8 @@ void luaG_errormsg (lua_State *L) {
546 if (L->errfunc != 0) { /* is there an error handling function? */ 546 if (L->errfunc != 0) { /* is there an error handling function? */
547 StkId errfunc = restorestack(L, L->errfunc); 547 StkId errfunc = restorestack(L, L->errfunc);
548 if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); 548 if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
549 setobjs2s(L->top, L->top - 1); /* move argument */ 549 setobjs2s(L, L->top, L->top - 1); /* move argument */
550 setobjs2s(L->top - 1, errfunc); /* push function */ 550 setobjs2s(L, L->top - 1, errfunc); /* push function */
551 incr_top(L); 551 incr_top(L);
552 luaD_call(L, L->top - 2, 1); /* call it */ 552 luaD_call(L, L->top - 2, 1); /* call it */
553 } 553 }
diff --git a/ldebug.h b/ldebug.h
index 03baaaee..b1c9ed2d 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 1.32 2002/11/18 11:01:55 roberto Exp $ 2** $Id: ldebug.h,v 1.33 2003/07/16 20:49:02 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -18,10 +18,10 @@
18#define resethookcount(L) (L->hookcount = L->basehookcount) 18#define resethookcount(L) (L->hookcount = L->basehookcount)
19 19
20 20
21void luaG_typeerror (lua_State *L, const TObject *o, const char *opname); 21void luaG_typeerror (lua_State *L, const TValue *o, const char *opname);
22void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 22void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
23void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2); 23void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2);
24int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); 24int luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2);
25void luaG_runerror (lua_State *L, const char *fmt, ...); 25void luaG_runerror (lua_State *L, const char *fmt, ...);
26void luaG_errormsg (lua_State *L); 26void luaG_errormsg (lua_State *L);
27int luaG_checkcode (const Proto *pt); 27int luaG_checkcode (const Proto *pt);
diff --git a/ldo.c b/ldo.c
index 02f8d53f..be24198b 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.228 2003/10/20 17:42:41 roberto Exp roberto $ 2** $Id: ldo.c,v 1.229 2003/11/11 16:34:17 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -64,16 +64,16 @@ struct lua_longjmp {
64static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { 64static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
65 switch (errcode) { 65 switch (errcode) {
66 case LUA_ERRMEM: { 66 case LUA_ERRMEM: {
67 setsvalue2s(oldtop, luaS_newliteral(L, MEMERRMSG)); 67 setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
68 break; 68 break;
69 } 69 }
70 case LUA_ERRERR: { 70 case LUA_ERRERR: {
71 setsvalue2s(oldtop, luaS_newliteral(L, "error in error handling")); 71 setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
72 break; 72 break;
73 } 73 }
74 case LUA_ERRSYNTAX: 74 case LUA_ERRSYNTAX:
75 case LUA_ERRRUN: { 75 case LUA_ERRRUN: {
76 setobjs2s(oldtop, L->top - 1); /* error message on current top */ 76 setobjs2s(L, oldtop, L->top - 1); /* error message on current top */
77 break; 77 break;
78 } 78 }
79 } 79 }
@@ -118,12 +118,12 @@ static void restore_stack_limit (lua_State *L) {
118/* }====================================================== */ 118/* }====================================================== */
119 119
120 120
121static void correctstack (lua_State *L, TObject *oldstack) { 121static void correctstack (lua_State *L, TValue *oldstack) {
122 CallInfo *ci; 122 CallInfo *ci;
123 GCObject *up; 123 GCObject *up;
124 L->top = (L->top - oldstack) + L->stack; 124 L->top = (L->top - oldstack) + L->stack;
125 for (up = L->openupval; up != NULL; up = up->gch.next) 125 for (up = L->openupval; up != NULL; up = up->gch.next)
126 gcotouv(up)->v = (gcotouv(up)->v - oldstack) + L->stack; 126 gco2uv(up)->v = (gco2uv(up)->v - oldstack) + L->stack;
127 for (ci = L->base_ci; ci <= L->ci; ci++) { 127 for (ci = L->base_ci; ci <= L->ci; ci++) {
128 ci->top = (ci->top - oldstack) + L->stack; 128 ci->top = (ci->top - oldstack) + L->stack;
129 ci->base = (ci->base - oldstack) + L->stack; 129 ci->base = (ci->base - oldstack) + L->stack;
@@ -133,8 +133,8 @@ static void correctstack (lua_State *L, TObject *oldstack) {
133 133
134 134
135void luaD_reallocstack (lua_State *L, int newsize) { 135void luaD_reallocstack (lua_State *L, int newsize) {
136 TObject *oldstack = L->stack; 136 TValue *oldstack = L->stack;
137 luaM_reallocvector(L, L->stack, L->stacksize, newsize, TObject); 137 luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue);
138 L->stacksize = newsize; 138 L->stacksize = newsize;
139 L->stack_last = L->stack+newsize-1-EXTRA_STACK; 139 L->stack_last = L->stack+newsize-1-EXTRA_STACK;
140 correctstack(L, oldstack); 140 correctstack(L, oldstack);
@@ -207,27 +207,28 @@ static void adjust_varargs (lua_State *L, int nfixargs, StkId base) {
207 actual -= nfixargs; /* number of extra arguments */ 207 actual -= nfixargs; /* number of extra arguments */
208 htab = luaH_new(L, actual, 1); /* create `arg' table */ 208 htab = luaH_new(L, actual, 1); /* create `arg' table */
209 for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ 209 for (i=0; i<actual; i++) /* put extra arguments into `arg' table */
210 setobj2n(luaH_setnum(L, htab, i+1), L->top - actual + i); 210 setobj2n(L, luaH_setnum(L, htab, i+1), L->top - actual + i);
211 /* store counter in field `n' */ 211 /* store counter in field `n' */
212 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), 212 setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")),
213 cast(lua_Number, actual)); 213 cast(lua_Number, actual));
214 L->top -= actual; /* remove extra elements from the stack */ 214 L->top -= actual; /* remove extra elements from the stack */
215 sethvalue(L->top, htab); 215 sethvalue(L, L->top, htab);
216 lua_assert(iswhite(obj2gco(htab)));
216 incr_top(L); 217 incr_top(L);
217} 218}
218 219
219 220
220static StkId tryfuncTM (lua_State *L, StkId func) { 221static StkId tryfuncTM (lua_State *L, StkId func) {
221 const TObject *tm = luaT_gettmbyobj(L, func, TM_CALL); 222 const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL);
222 StkId p; 223 StkId p;
223 ptrdiff_t funcr = savestack(L, func); 224 ptrdiff_t funcr = savestack(L, func);
224 if (!ttisfunction(tm)) 225 if (!ttisfunction(tm))
225 luaG_typeerror(L, func, "call"); 226 luaG_typeerror(L, func, "call");
226 /* Open a hole inside the stack at `func' */ 227 /* Open a hole inside the stack at `func' */
227 for (p = L->top; p > func; p--) setobjs2s(p, p-1); 228 for (p = L->top; p > func; p--) setobjs2s(L, p, p-1);
228 incr_top(L); 229 incr_top(L);
229 func = restorestack(L, funcr); /* previous call may change stack */ 230 func = restorestack(L, funcr); /* previous call may change stack */
230 setobj2s(func, tm); /* tag method is the new function to be called */ 231 setobj2s(L, func, tm); /* tag method is the new function to be called */
231 return func; 232 return func;
232} 233}
233 234
@@ -294,7 +295,7 @@ void luaD_poscall (lua_State *L, int wanted, StkId firstResult) {
294 L->base = L->ci->base; /* restore base */ 295 L->base = L->ci->base; /* restore base */
295 /* move results to correct place */ 296 /* move results to correct place */
296 while (wanted != 0 && firstResult < L->top) { 297 while (wanted != 0 && firstResult < L->top) {
297 setobjs2s(res++, firstResult++); 298 setobjs2s(L, res++, firstResult++);
298 wanted--; 299 wanted--;
299 } 300 }
300 while (wanted-- > 0) 301 while (wanted-- > 0)
@@ -354,7 +355,7 @@ static void resume (lua_State *L, void *ud) {
354 355
355static int resume_error (lua_State *L, const char *msg) { 356static int resume_error (lua_State *L, const char *msg) {
356 L->top = L->ci->base; 357 L->top = L->ci->base;
357 setsvalue2s(L->top, luaS_new(L, msg)); 358 setsvalue2s(L, L->top, luaS_new(L, msg));
358 incr_top(L); 359 incr_top(L);
359 lua_unlock(L); 360 lua_unlock(L);
360 return LUA_ERRRUN; 361 return LUA_ERRRUN;
@@ -400,7 +401,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) {
400 if (L->top - nresults > L->base) { /* is there garbage in the stack? */ 401 if (L->top - nresults > L->base) { /* is there garbage in the stack? */
401 int i; 402 int i;
402 for (i=0; i<nresults; i++) /* move down results */ 403 for (i=0; i<nresults; i++) /* move down results */
403 setobjs2s(L->base + i, L->top - nresults + i); 404 setobjs2s(L, L->base + i, L->top - nresults + i);
404 L->top = L->base + nresults; 405 L->top = L->base + nresults;
405 } 406 }
406 } /* else it's an yield inside a hook: nothing to do */ 407 } /* else it's an yield inside a hook: nothing to do */
@@ -457,7 +458,7 @@ static void f_parser (lua_State *L, void *ud) {
457 cl->l.p = tf; 458 cl->l.p = tf;
458 for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ 459 for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */
459 cl->l.upvals[i] = luaF_newupval(L); 460 cl->l.upvals[i] = luaF_newupval(L);
460 setclvalue(L->top, cl); 461 setclvalue(L, L->top, cl);
461 incr_top(L); 462 incr_top(L);
462} 463}
463 464
diff --git a/ldo.h b/ldo.h
index f3d528be..fc13692c 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 1.57 2003/08/25 19:51:54 roberto Exp roberto $ 2** $Id: ldo.h,v 1.58 2003/08/27 21:01:44 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,7 +24,7 @@
24 24
25 25
26#define luaD_checkstack(L,n) \ 26#define luaD_checkstack(L,n) \
27 if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TObject)) \ 27 if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
28 luaD_growstack(L, n); \ 28 luaD_growstack(L, n); \
29 else condhardstacktests(luaD_reallocstack(L, L->stacksize)); 29 else condhardstacktests(luaD_reallocstack(L, L->stacksize));
30 30
@@ -32,7 +32,7 @@
32#define incr_top(L) {luaD_checkstack(L,1); L->top++;} 32#define incr_top(L) {luaD_checkstack(L,1); L->top++;}
33 33
34#define savestack(L,p) ((char *)(p) - (char *)L->stack) 34#define savestack(L,p) ((char *)(p) - (char *)L->stack)
35#define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) 35#define restorestack(L,n) ((TValue *)((char *)L->stack + (n)))
36 36
37#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 37#define saveci(L,p) ((char *)(p) - (char *)L->base_ci)
38#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 38#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n)))
diff --git a/ldump.c b/ldump.c
index 4cf55e09..24367891 100644
--- a/ldump.c
+++ b/ldump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldump.c,v 1.4 2003/02/11 23:52:12 lhf Exp lhf $ 2** $Id: ldump.c,v 1.6 2003/08/15 13:48:53 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*/
@@ -104,7 +104,7 @@ static void DumpConstants(const Proto* f, DumpState* D)
104 DumpInt(n=f->sizek,D); 104 DumpInt(n=f->sizek,D);
105 for (i=0; i<n; i++) 105 for (i=0; i<n; i++)
106 { 106 {
107 const TObject* o=&f->k[i]; 107 const TValue* o=&f->k[i];
108 DumpByte(ttype(o),D); 108 DumpByte(ttype(o),D);
109 switch (ttype(o)) 109 switch (ttype(o))
110 { 110 {
@@ -112,7 +112,7 @@ static void DumpConstants(const Proto* f, DumpState* D)
112 DumpNumber(nvalue(o),D); 112 DumpNumber(nvalue(o),D);
113 break; 113 break;
114 case LUA_TSTRING: 114 case LUA_TSTRING:
115 DumpString(tsvalue(o),D); 115 DumpString(rawtsvalue(o),D);
116 break; 116 break;
117 case LUA_TNIL: 117 case LUA_TNIL:
118 break; 118 break;
diff --git a/lfunc.c b/lfunc.c
index 77193ad7..af27bf0d 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.73 2003/12/03 20:03:07 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.74 2003/12/09 16:56:11 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,16 +21,16 @@
21 21
22Closure *luaF_newCclosure (lua_State *L, int nelems) { 22Closure *luaF_newCclosure (lua_State *L, int nelems) {
23 Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems))); 23 Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
24 luaC_link(L, valtogco(c), LUA_TFUNCTION); 24 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
25 c->c.isC = 1; 25 c->c.isC = 1;
26 c->c.nupvalues = cast(lu_byte, nelems); 26 c->c.nupvalues = cast(lu_byte, nelems);
27 return c; 27 return c;
28} 28}
29 29
30 30
31Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) { 31Closure *luaF_newLclosure (lua_State *L, int nelems, TValue *e) {
32 Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems))); 32 Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
33 luaC_link(L, valtogco(c), LUA_TFUNCTION); 33 luaC_link(L, obj2gco(c), LUA_TFUNCTION);
34 c->l.isC = 0; 34 c->l.isC = 0;
35 c->l.g = *e; 35 c->l.g = *e;
36 c->l.nupvalues = cast(lu_byte, nelems); 36 c->l.nupvalues = cast(lu_byte, nelems);
@@ -40,7 +40,7 @@ Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) {
40 40
41UpVal *luaF_newupval (lua_State *L) { 41UpVal *luaF_newupval (lua_State *L) {
42 UpVal *uv = luaM_new(L, UpVal); 42 UpVal *uv = luaM_new(L, UpVal);
43 luaC_link(L, valtogco(uv), LUA_TUPVAL); 43 luaC_link(L, obj2gco(uv), LUA_TUPVAL);
44 uv->v = &uv->value; 44 uv->v = &uv->value;
45 setnilvalue(uv->v); 45 setnilvalue(uv->v);
46 return uv; 46 return uv;
@@ -60,7 +60,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
60 uv->marked = bitmask(FIXEDBIT); /* open upvalues cannot be collected */ 60 uv->marked = bitmask(FIXEDBIT); /* open upvalues cannot be collected */
61 uv->v = level; /* current value lives in the stack */ 61 uv->v = level; /* current value lives in the stack */
62 uv->next = *pp; /* chain it in the proper position */ 62 uv->next = *pp; /* chain it in the proper position */
63 *pp = valtogco(uv); 63 *pp = obj2gco(uv);
64 return uv; 64 return uv;
65} 65}
66 66
@@ -68,18 +68,18 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
68void luaF_close (lua_State *L, StkId level) { 68void luaF_close (lua_State *L, StkId level) {
69 UpVal *uv; 69 UpVal *uv;
70 while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { 70 while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) {
71 setobj(&uv->value, uv->v); 71 setobj(L, &uv->value, uv->v);
72 luaC_barrier(L, uv, uv->v); 72 luaC_barrier(L, uv, uv->v);
73 uv->v = &uv->value; /* now current value lives here */ 73 uv->v = &uv->value; /* now current value lives here */
74 L->openupval = uv->next; /* remove from `open' list */ 74 L->openupval = uv->next; /* remove from `open' list */
75 luaC_link(L, valtogco(uv), LUA_TUPVAL); 75 luaC_link(L, obj2gco(uv), LUA_TUPVAL);
76 } 76 }
77} 77}
78 78
79 79
80Proto *luaF_newproto (lua_State *L) { 80Proto *luaF_newproto (lua_State *L) {
81 Proto *f = luaM_new(L, Proto); 81 Proto *f = luaM_new(L, Proto);
82 luaC_link(L, valtogco(f), LUA_TPROTO); 82 luaC_link(L, obj2gco(f), LUA_TPROTO);
83 f->k = NULL; 83 f->k = NULL;
84 f->sizek = 0; 84 f->sizek = 0;
85 f->p = NULL; 85 f->p = NULL;
@@ -105,7 +105,7 @@ Proto *luaF_newproto (lua_State *L) {
105void luaF_freeproto (lua_State *L, Proto *f) { 105void luaF_freeproto (lua_State *L, Proto *f) {
106 luaM_freearray(L, f->code, f->sizecode, Instruction); 106 luaM_freearray(L, f->code, f->sizecode, Instruction);
107 luaM_freearray(L, f->p, f->sizep, Proto *); 107 luaM_freearray(L, f->p, f->sizep, Proto *);
108 luaM_freearray(L, f->k, f->sizek, TObject); 108 luaM_freearray(L, f->k, f->sizek, TValue);
109 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int); 109 luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
110 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar); 110 luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
111 luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *); 111 luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
diff --git a/lfunc.h b/lfunc.h
index bb0fa001..c6e35586 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.h,v 1.22 2003/10/20 17:42:41 roberto Exp roberto $ 2** $Id: lfunc.h,v 1.23 2003/11/24 18:50:36 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*/
@@ -12,15 +12,15 @@
12 12
13 13
14#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 14#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
15 cast(int, sizeof(TObject)*((n)-1))) 15 cast(int, sizeof(TValue)*((n)-1)))
16 16
17#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 17#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
18 cast(int, sizeof(TObject *)*((n)-1))) 18 cast(int, sizeof(TValue *)*((n)-1)))
19 19
20 20
21Proto *luaF_newproto (lua_State *L); 21Proto *luaF_newproto (lua_State *L);
22Closure *luaF_newCclosure (lua_State *L, int nelems); 22Closure *luaF_newCclosure (lua_State *L, int nelems);
23Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e); 23Closure *luaF_newLclosure (lua_State *L, int nelems, TValue *e);
24UpVal *luaF_newupval (lua_State *L); 24UpVal *luaF_newupval (lua_State *L);
25UpVal *luaF_findupval (lua_State *L, StkId level); 25UpVal *luaF_findupval (lua_State *L, StkId level);
26void luaF_close (lua_State *L, StkId level); 26void luaF_close (lua_State *L, StkId level);
diff --git a/lgc.c b/lgc.c
index 8cb8620f..147593b0 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.186 2003/12/04 18:52:23 roberto Exp roberto $ 2** $Id: lgc.c,v 1.187 2003/12/09 16:56:11 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*/
@@ -22,7 +22,7 @@
22#include "ltm.h" 22#include "ltm.h"
23 23
24 24
25#define GCSTEPSIZE (20*sizeof(TObject)) 25#define GCSTEPSIZE (20*sizeof(TValue))
26 26
27 27
28#define gray2black(x) setbit((x)->gch.marked, BLACKBIT) 28#define gray2black(x) setbit((x)->gch.marked, BLACKBIT)
@@ -39,8 +39,8 @@
39#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) 39#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
40 40
41 41
42#define isfinalized(u) testbit((u)->uv.marked, FINALIZEDBIT) 42#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT)
43#define markfinalized(u) setbit((u)->uv.marked, FINALIZEDBIT) 43#define markfinalized(u) setbit((u)->marked, FINALIZEDBIT)
44 44
45 45
46#define KEYWEAK bitmask(KEYWEAKBIT) 46#define KEYWEAK bitmask(KEYWEAKBIT)
@@ -55,8 +55,8 @@
55 if (iscollectable(o) && iswhite(gcvalue(o)) && (c)) \ 55 if (iscollectable(o) && iswhite(gcvalue(o)) && (c)) \
56 reallymarkobject(g,gcvalue(o)); } 56 reallymarkobject(g,gcvalue(o)); }
57 57
58#define markobject(g,t) { if (iswhite(valtogco(t))) \ 58#define markobject(g,t) { if (iswhite(obj2gco(t))) \
59 reallymarkobject(g, valtogco(t)); } 59 reallymarkobject(g, obj2gco(t)); }
60 60
61 61
62 62
@@ -66,34 +66,34 @@
66static size_t objsize (GCObject *o) { 66static size_t objsize (GCObject *o) {
67 switch (o->gch.tt) { 67 switch (o->gch.tt) {
68 case LUA_TSTRING: { 68 case LUA_TSTRING: {
69 TString *ts = gcotots(o); 69 TString *ts = rawgco2ts(o);
70 return sizestring(ts->tsv.len); 70 return sizestring(ts->tsv.len);
71 } 71 }
72 case LUA_TUSERDATA: { 72 case LUA_TUSERDATA: {
73 Udata *u = gcotou(o); 73 Udata *u = rawgco2u(o);
74 return sizeudata(u->uv.len); 74 return sizeudata(u->uv.len);
75 } 75 }
76 case LUA_TTABLE: { 76 case LUA_TTABLE: {
77 Table *h = gcotoh(o); 77 Table *h = gco2h(o);
78 return sizeof(Table) + sizeof(TObject) * h->sizearray + 78 return sizeof(Table) + sizeof(TValue) * h->sizearray +
79 sizeof(Node) * sizenode(h); 79 sizeof(Node) * sizenode(h);
80 } 80 }
81 case LUA_TUPVAL: 81 case LUA_TUPVAL:
82 return sizeof(UpVal); 82 return sizeof(UpVal);
83 case LUA_TFUNCTION: { 83 case LUA_TFUNCTION: {
84 Closure *cl = gcotocl(o); 84 Closure *cl = gco2cl(o);
85 return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) : 85 return (cl->c.isC) ? sizeCclosure(cl->c.nupvalues) :
86 sizeLclosure(cl->l.nupvalues); 86 sizeLclosure(cl->l.nupvalues);
87 } 87 }
88 case LUA_TTHREAD: { 88 case LUA_TTHREAD: {
89 lua_State *th = gcototh(o); 89 lua_State *th = gco2th(o);
90 return sizeof(lua_State) + sizeof(TObject) * th->stacksize + 90 return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
91 sizeof(CallInfo) * th->size_ci; 91 sizeof(CallInfo) * th->size_ci;
92 } 92 }
93 case LUA_TPROTO: { 93 case LUA_TPROTO: {
94 Proto *p = gcotop(o); 94 Proto *p = gco2p(o);
95 return sizeof(Proto) + sizeof(Instruction) * p->sizecode + 95 return sizeof(Proto) + sizeof(Instruction) * p->sizecode +
96 sizeof(Proto *) * p->sizep + sizeof(TObject) * p->sizek + 96 sizeof(Proto *) * p->sizep + sizeof(TValue) * p->sizek +
97 sizeof(int) * p->sizelineinfo + sizeof(LocVar) * p->sizelocvars + 97 sizeof(int) * p->sizelineinfo + sizeof(LocVar) * p->sizelocvars +
98 sizeof(TString *) * p->sizeupvalues; 98 sizeof(TString *) * p->sizeupvalues;
99 } 99 }
@@ -112,29 +112,29 @@ static void reallymarkobject (global_State *g, GCObject *o) {
112 return; 112 return;
113 } 113 }
114 case LUA_TUSERDATA: { 114 case LUA_TUSERDATA: {
115 Table *mt = gcotou(o)->uv.metatable; 115 Table *mt = gco2u(o)->metatable;
116 gray2black(o); /* udata are never gray */ 116 gray2black(o); /* udata are never gray */
117 if (mt) markobject(g, mt); 117 if (mt) markobject(g, mt);
118 return; 118 return;
119 } 119 }
120 case LUA_TFUNCTION: { 120 case LUA_TFUNCTION: {
121 gcotocl(o)->c.gclist = g->gray; 121 gco2cl(o)->c.gclist = g->gray;
122 break; 122 break;
123 } 123 }
124 case LUA_TTABLE: { 124 case LUA_TTABLE: {
125 gcotoh(o)->gclist = g->gray; 125 gco2h(o)->gclist = g->gray;
126 break; 126 break;
127 } 127 }
128 case LUA_TTHREAD: { 128 case LUA_TTHREAD: {
129 gcototh(o)->gclist = g->gray; 129 gco2th(o)->gclist = g->gray;
130 break; 130 break;
131 } 131 }
132 case LUA_TPROTO: { 132 case LUA_TPROTO: {
133 gcotop(o)->gclist = g->gray; 133 gco2p(o)->gclist = g->gray;
134 break; 134 break;
135 } 135 }
136 case LUA_TUPVAL: { 136 case LUA_TUPVAL: {
137 gcotouv(o)->gclist = g->gray; 137 gco2uv(o)->gclist = g->gray;
138 break; 138 break;
139 } 139 }
140 default: lua_assert(0); 140 default: lua_assert(0);
@@ -161,15 +161,15 @@ size_t luaC_separateudata (lua_State *L) {
161 GCObject **lastcollected = &collected; 161 GCObject **lastcollected = &collected;
162 while ((curr = *p) != NULL) { 162 while ((curr = *p) != NULL) {
163 lua_assert(curr->gch.tt == LUA_TUSERDATA); 163 lua_assert(curr->gch.tt == LUA_TUSERDATA);
164 if (!iswhite(curr) || isfinalized(gcotou(curr))) 164 if (!iswhite(curr) || isfinalized(gco2u(curr)))
165 p = &curr->gch.next; /* don't bother with them */ 165 p = &curr->gch.next; /* don't bother with them */
166 else if (fasttm(L, gcotou(curr)->uv.metatable, TM_GC) == NULL) { 166 else if (fasttm(L, gco2u(curr)->metatable, TM_GC) == NULL) {
167 markfinalized(gcotou(curr)); /* don't need finalization */ 167 markfinalized(gco2u(curr)); /* don't need finalization */
168 p = &curr->gch.next; 168 p = &curr->gch.next;
169 } 169 }
170 else { /* must call its gc method */ 170 else { /* must call its gc method */
171 deadmem += sizeudata(gcotou(curr)->uv.len); 171 deadmem += sizeudata(gco2u(curr)->len);
172 markfinalized(gcotou(curr)); 172 markfinalized(gco2u(curr));
173 *p = curr->gch.next; 173 *p = curr->gch.next;
174 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */ 174 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
175 *lastcollected = curr; 175 *lastcollected = curr;
@@ -187,7 +187,7 @@ static void traversetable (global_State *g, Table *h) {
187 int i; 187 int i;
188 int weakkey = 0; 188 int weakkey = 0;
189 int weakvalue = 0; 189 int weakvalue = 0;
190 const TObject *mode; 190 const TValue *mode;
191 if (h->metatable) 191 if (h->metatable)
192 markobject(g, h->metatable); 192 markobject(g, h->metatable);
193 lua_assert(h->lsizenode || h->node == g->dummynode); 193 lua_assert(h->lsizenode || h->node == g->dummynode);
@@ -200,7 +200,7 @@ static void traversetable (global_State *g, Table *h) {
200 h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) | 200 h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) |
201 (weakvalue << VALUEWEAKBIT)); 201 (weakvalue << VALUEWEAKBIT));
202 h->gclist = g->weak; /* must be cleared after GC, ... */ 202 h->gclist = g->weak; /* must be cleared after GC, ... */
203 g->weak = valtogco(h); /* ... so put in the appropriate list */ 203 g->weak = obj2gco(h); /* ... so put in the appropriate list */
204 } 204 }
205 } 205 }
206 if (weakkey && weakvalue) return; 206 if (weakkey && weakvalue) return;
@@ -230,7 +230,7 @@ static void traverseproto (global_State *g, Proto *f) {
230 if (f->source) stringmark(f->source); 230 if (f->source) stringmark(f->source);
231 for (i=0; i<f->sizek; i++) { /* mark literal strings */ 231 for (i=0; i<f->sizek; i++) { /* mark literal strings */
232 if (ttisstring(f->k+i)) 232 if (ttisstring(f->k+i))
233 stringmark(tsvalue(f->k+i)); 233 stringmark(rawtsvalue(f->k+i));
234 } 234 }
235 for (i=0; i<f->sizeupvalues; i++) { /* mark upvalue names */ 235 for (i=0; i<f->sizeupvalues; i++) { /* mark upvalue names */
236 if (f->upvalues[i]) 236 if (f->upvalues[i])
@@ -306,19 +306,19 @@ static l_mem propagatemarks (global_State *g, l_mem lim) {
306 gray2black(o); 306 gray2black(o);
307 switch (o->gch.tt) { 307 switch (o->gch.tt) {
308 case LUA_TTABLE: { 308 case LUA_TTABLE: {
309 Table *h = gcotoh(o); 309 Table *h = gco2h(o);
310 g->gray = h->gclist; 310 g->gray = h->gclist;
311 traversetable(g, h); 311 traversetable(g, h);
312 break; 312 break;
313 } 313 }
314 case LUA_TFUNCTION: { 314 case LUA_TFUNCTION: {
315 Closure *cl = gcotocl(o); 315 Closure *cl = gco2cl(o);
316 g->gray = cl->c.gclist; 316 g->gray = cl->c.gclist;
317 traverseclosure(g, cl); 317 traverseclosure(g, cl);
318 break; 318 break;
319 } 319 }
320 case LUA_TTHREAD: { 320 case LUA_TTHREAD: {
321 lua_State *th = gcototh(o); 321 lua_State *th = gco2th(o);
322 g->gray = th->gclist; 322 g->gray = th->gclist;
323 th->gclist = g->grayagain; 323 th->gclist = g->grayagain;
324 g->grayagain = o; 324 g->grayagain = o;
@@ -327,13 +327,13 @@ static l_mem propagatemarks (global_State *g, l_mem lim) {
327 break; 327 break;
328 } 328 }
329 case LUA_TPROTO: { 329 case LUA_TPROTO: {
330 Proto *p = gcotop(o); 330 Proto *p = gco2p(o);
331 g->gray = p->gclist; 331 g->gray = p->gclist;
332 traverseproto(g, p); 332 traverseproto(g, p);
333 break; 333 break;
334 } 334 }
335 case LUA_TUPVAL: { 335 case LUA_TUPVAL: {
336 UpVal *uv = gcotouv(o); 336 UpVal *uv = gco2uv(o);
337 g->gray = uv->gclist; 337 g->gray = uv->gclist;
338 if (uv->v != &uv->value) { /* open? */ 338 if (uv->v != &uv->value) { /* open? */
339 uv->gclist = g->grayagain; 339 uv->gclist = g->grayagain;
@@ -360,10 +360,10 @@ static l_mem propagatemarks (global_State *g, l_mem lim) {
360** other objects: if really collected, cannot keep them; for userdata 360** other objects: if really collected, cannot keep them; for userdata
361** being finalized, keep them in keys, but not in values 361** being finalized, keep them in keys, but not in values
362*/ 362*/
363static int iscleared (const TObject *o, int iskey) { 363static int iscleared (const TValue *o, int iskey) {
364 if (!iscollectable(o)) return 0; 364 if (!iscollectable(o)) return 0;
365 if (ttisstring(o)) { 365 if (ttisstring(o)) {
366 stringmark(tsvalue(o)); /* strings are `values', so are never weak */ 366 stringmark(rawtsvalue(o)); /* strings are `values', so are never weak */
367 return 0; 367 return 0;
368 } 368 }
369 return iswhite(gcvalue(o)) || 369 return iswhite(gcvalue(o)) ||
@@ -383,13 +383,13 @@ static void removekey (Node *n) {
383*/ 383*/
384static void cleartable (GCObject *l) { 384static void cleartable (GCObject *l) {
385 while (l) { 385 while (l) {
386 Table *h = gcotoh(l); 386 Table *h = gco2h(l);
387 int i = h->sizearray; 387 int i = h->sizearray;
388 lua_assert(testbit(h->marked, VALUEWEAKBIT) || 388 lua_assert(testbit(h->marked, VALUEWEAKBIT) ||
389 testbit(h->marked, KEYWEAKBIT)); 389 testbit(h->marked, KEYWEAKBIT));
390 if (testbit(h->marked, VALUEWEAKBIT)) { 390 if (testbit(h->marked, VALUEWEAKBIT)) {
391 while (i--) { 391 while (i--) {
392 TObject *o = &h->array[i]; 392 TValue *o = &h->array[i];
393 if (iscleared(o, 0)) /* value was collected? */ 393 if (iscleared(o, 0)) /* value was collected? */
394 setnilvalue(o); /* remove value */ 394 setnilvalue(o); /* remove value */
395 } 395 }
@@ -408,21 +408,21 @@ static void cleartable (GCObject *l) {
408 408
409static void freeobj (lua_State *L, GCObject *o) { 409static void freeobj (lua_State *L, GCObject *o) {
410 switch (o->gch.tt) { 410 switch (o->gch.tt) {
411 case LUA_TPROTO: luaF_freeproto(L, gcotop(o)); break; 411 case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
412 case LUA_TFUNCTION: luaF_freeclosure(L, gcotocl(o)); break; 412 case LUA_TFUNCTION: luaF_freeclosure(L, gco2cl(o)); break;
413 case LUA_TUPVAL: luaM_freelem(L, gcotouv(o)); break; 413 case LUA_TUPVAL: luaM_freelem(L, gco2uv(o)); break;
414 case LUA_TTABLE: luaH_free(L, gcotoh(o)); break; 414 case LUA_TTABLE: luaH_free(L, gco2h(o)); break;
415 case LUA_TTHREAD: { 415 case LUA_TTHREAD: {
416 lua_assert(gcototh(o) != L && gcototh(o) != G(L)->mainthread); 416 lua_assert(gco2th(o) != L && gco2th(o) != G(L)->mainthread);
417 luaE_freethread(L, gcototh(o)); 417 luaE_freethread(L, gco2th(o));
418 break; 418 break;
419 } 419 }
420 case LUA_TSTRING: { 420 case LUA_TSTRING: {
421 luaM_free(L, o, sizestring(gcotots(o)->tsv.len)); 421 luaM_free(L, o, sizestring(gco2ts(o)->len));
422 break; 422 break;
423 } 423 }
424 case LUA_TUSERDATA: { 424 case LUA_TUSERDATA: {
425 luaM_free(L, o, sizeudata(gcotou(o)->uv.len)); 425 luaM_free(L, o, sizeudata(gco2u(o)->len));
426 break; 426 break;
427 } 427 }
428 default: lua_assert(0); 428 default: lua_assert(0);
@@ -463,7 +463,7 @@ static l_mem sweepstrings (lua_State *L, int all, l_mem lim) {
463 GCObject **p = &G(L)->strt.hash[i]; 463 GCObject **p = &G(L)->strt.hash[i];
464 while ((curr = *p) != NULL) { 464 while ((curr = *p) != NULL) {
465 int mark = curr->gch.marked; 465 int mark = curr->gch.marked;
466 lu_mem size = sizestring(gcotots(curr)->tsv.len); 466 lu_mem size = sizestring(gco2ts(curr)->len);
467 if (!all && (!(mark & dead) || testbit(mark, FIXEDBIT))) { 467 if (!all && (!(mark & dead) || testbit(mark, FIXEDBIT))) {
468 makewhite(g, curr); 468 makewhite(g, curr);
469 lua_assert(iswhite(curr) && !isdead(g, curr)); 469 lua_assert(iswhite(curr) && !isdead(g, curr));
@@ -503,8 +503,8 @@ static void GCTM (lua_State *L) {
503 g->gcstate = GCSroot; /* will restart GC */ 503 g->gcstate = GCSroot; /* will restart GC */
504 else { 504 else {
505 GCObject *o = g->tmudata; 505 GCObject *o = g->tmudata;
506 Udata *udata = gcotou(o); 506 Udata *udata = rawgco2u(o);
507 const TObject *tm; 507 const TValue *tm;
508 g->tmudata = udata->uv.next; /* remove udata from `tmudata' */ 508 g->tmudata = udata->uv.next; /* remove udata from `tmudata' */
509 udata->uv.next = g->firstudata->uv.next; /* return it to `root' list */ 509 udata->uv.next = g->firstudata->uv.next; /* return it to `root' list */
510 g->firstudata->uv.next = o; 510 g->firstudata->uv.next = o;
@@ -513,8 +513,8 @@ static void GCTM (lua_State *L) {
513 if (tm != NULL) { 513 if (tm != NULL) {
514 lu_byte oldah = L->allowhook; 514 lu_byte oldah = L->allowhook;
515 L->allowhook = 0; /* stop debug hooks during GC tag method */ 515 L->allowhook = 0; /* stop debug hooks during GC tag method */
516 setobj2s(L->top, tm); 516 setobj2s(L, L->top, tm);
517 setuvalue(L->top+1, udata); 517 setuvalue(L, L->top+1, udata);
518 L->top += 2; 518 L->top += 2;
519 luaD_call(L, L->top - 2, 0); 519 luaD_call(L, L->top - 2, 0);
520 L->allowhook = oldah; /* restore hooks */ 520 L->allowhook = oldah; /* restore hooks */
@@ -545,7 +545,7 @@ static void markroot (lua_State *L) {
545 global_State *g = G(L); 545 global_State *g = G(L);
546 lua_assert(g->gray == NULL); 546 lua_assert(g->gray == NULL);
547 g->weak = NULL; 547 g->weak = NULL;
548 makewhite(g, valtogco(g->mainthread)); 548 makewhite(g, obj2gco(g->mainthread));
549 markobject(g, g->mainthread); 549 markobject(g, g->mainthread);
550 markvalue(g, registry(L)); 550 markvalue(g, registry(L));
551 markobject(g, L); /* mark running thread */ 551 markobject(g, L); /* mark running thread */
diff --git a/lgc.h b/lgc.h
index ff1e1115..e20f2afb 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 1.27 2003/12/04 17:22:42 roberto Exp roberto $ 2** $Id: lgc.h,v 1.28 2003/12/09 16:56:11 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*/
@@ -76,12 +76,12 @@
76 luaC_step(L); } 76 luaC_step(L); }
77 77
78 78
79#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(valtogco(p))) \ 79#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
80 luaC_barrierf(L,valtogco(p),gcvalue(v)); } 80 luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
81 81
82#define luaC_objbarrier(L,p,o) \ 82#define luaC_objbarrier(L,p,o) \
83 { if (iswhite(valtogco(o)) && isblack(valtogco(p))) \ 83 { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
84 luaC_barrierf(L,valtogco(p),valtogco(o)); } 84 luaC_barrierf(L,obj2gco(p),obj2gco(o)); }
85 85
86size_t luaC_separateudata (lua_State *L); 86size_t luaC_separateudata (lua_State *L);
87void luaC_callGCTM (lua_State *L); 87void luaC_callGCTM (lua_State *L);
diff --git a/llex.c b/llex.c
index e4b2d74f..bb83571e 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.127 2003/10/03 16:07:44 roberto Exp roberto $ 2** $Id: llex.c,v 1.128 2003/10/20 12:24:34 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -110,7 +110,7 @@ void luaX_syntaxerror (LexState *ls, const char *msg) {
110TString *luaX_newstring (LexState *ls, const char *str, size_t l) { 110TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
111 lua_State *L = ls->L; 111 lua_State *L = ls->L;
112 TString *ts = luaS_newlstr(L, str, l); 112 TString *ts = luaS_newlstr(L, str, l);
113 TObject *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ 113 TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
114 if (ttisnil(o)) 114 if (ttisnil(o))
115 setbvalue(o, 1); /* make sure `str' will not be collected */ 115 setbvalue(o, 1); /* make sure `str' will not be collected */
116 return ts; 116 return ts;
diff --git a/lobject.c b/lobject.c
index 28ae45c5..cce60d92 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.98 2003/04/28 13:30:14 roberto Exp roberto $ 2** $Id: lobject.c,v 1.99 2003/06/10 12:36:26 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -27,7 +27,7 @@
27#endif 27#endif
28 28
29 29
30const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; 30const TValue luaO_nilobject = {LUA_TNIL, {NULL}};
31 31
32 32
33/* 33/*
@@ -62,7 +62,7 @@ int luaO_log2 (unsigned int x) {
62} 62}
63 63
64 64
65int luaO_rawequalObj (const TObject *t1, const TObject *t2) { 65int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
66 if (ttype(t1) != ttype(t2)) return 0; 66 if (ttype(t1) != ttype(t2)) return 0;
67 else switch (ttype(t1)) { 67 else switch (ttype(t1)) {
68 case LUA_TNIL: 68 case LUA_TNIL:
@@ -93,7 +93,7 @@ int luaO_str2d (const char *s, lua_Number *result) {
93 93
94 94
95static void pushstr (lua_State *L, const char *str) { 95static void pushstr (lua_State *L, const char *str) {
96 setsvalue2s(L->top, luaS_new(L, str)); 96 setsvalue2s(L, L->top, luaS_new(L, str));
97 incr_top(L); 97 incr_top(L);
98} 98}
99 99
@@ -105,7 +105,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
105 for (;;) { 105 for (;;) {
106 const char *e = strchr(fmt, '%'); 106 const char *e = strchr(fmt, '%');
107 if (e == NULL) break; 107 if (e == NULL) break;
108 setsvalue2s(L->top, luaS_newlstr(L, fmt, e-fmt)); 108 setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
109 incr_top(L); 109 incr_top(L);
110 switch (*(e+1)) { 110 switch (*(e+1)) {
111 case 's': 111 case 's':
diff --git a/lobject.h b/lobject.h
index b2987429..fa5364c2 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.161 2003/08/27 21:01:44 roberto Exp roberto $ 2** $Id: lobject.h,v 1.162 2003/11/18 14:55:11 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*/
@@ -58,12 +58,12 @@ typedef union {
58 58
59 59
60/* 60/*
61** Lua values (or `tagged objects') 61** Tagged Values
62*/ 62*/
63typedef struct lua_TObject { 63typedef struct lua_TValue {
64 int tt; 64 int tt;
65 Value value; 65 Value value;
66} TObject; 66} TValue;
67 67
68 68
69/* Macros to test type */ 69/* Macros to test type */
@@ -82,8 +82,10 @@ typedef struct lua_TObject {
82#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) 82#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc)
83#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) 83#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
84#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) 84#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
85#define tsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) 85#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
86#define uvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) 86#define tsvalue(o) (&rawtsvalue(o)->tsv)
87#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
88#define uvalue(o) (&rawuvalue(o)->uv)
87#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) 89#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
88#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) 90#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
89#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) 91#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
@@ -91,64 +93,69 @@ typedef struct lua_TObject {
91 93
92#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) 94#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
93 95
96/*
97** for internal debug only
98*/
99#define checkconsistency(obj) \
100 lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
101
102#define checkliveness(L,obj) \
103 lua_assert(!iscollectable(obj) || \
104 ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(G(L), (obj)->value.gc)))
105
106
94/* Macros to set values */ 107/* Macros to set values */
95#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) 108#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
96 109
97#define setnvalue(obj,x) \ 110#define setnvalue(obj,x) \
98 { TObject *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } 111 { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
99 112
100#define chgnvalue(obj,x) \ 113#define chgnvalue(obj,x) \
101 check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x)) 114 check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x))
102 115
103#define setpvalue(obj,x) \ 116#define setpvalue(obj,x) \
104 { TObject *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } 117 { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
105 118
106#define setbvalue(obj,x) \ 119#define setbvalue(obj,x) \
107 { TObject *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } 120 { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }
108 121
109#define setsvalue(obj,x) \ 122#define setsvalue(L,obj,x) \
110 { TObject *i_o=(obj); \ 123 { TValue *i_o=(obj); \
111 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ 124 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \
112 lua_assert(i_o->value.gc->gch.tt == LUA_TSTRING); } 125 checkliveness(L,i_o); }
113 126
114#define setuvalue(obj,x) \ 127#define setuvalue(L,obj,x) \
115 { TObject *i_o=(obj); \ 128 { TValue *i_o=(obj); \
116 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ 129 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \
117 lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); } 130 checkliveness(L,i_o); }
118 131
119#define setthvalue(obj,x) \ 132#define setthvalue(L,obj,x) \
120 { TObject *i_o=(obj); \ 133 { TValue *i_o=(obj); \
121 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ 134 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \
122 lua_assert(i_o->value.gc->gch.tt == LUA_TTHREAD); } 135 checkliveness(L,i_o); }
123 136
124#define setclvalue(obj,x) \ 137#define setclvalue(L,obj,x) \
125 { TObject *i_o=(obj); \ 138 { TValue *i_o=(obj); \
126 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ 139 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \
127 lua_assert(i_o->value.gc->gch.tt == LUA_TFUNCTION); } 140 checkliveness(L,i_o); }
128 141
129#define sethvalue(obj,x) \ 142#define sethvalue(L,obj,x) \
130 { TObject *i_o=(obj); \ 143 { TValue *i_o=(obj); \
131 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ 144 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \
132 lua_assert(i_o->value.gc->gch.tt == LUA_TTABLE); } 145 checkliveness(L,i_o); }
133 146
134#define setptvalue(obj,x) \ 147#define setptvalue(L,obj,x) \
135 { TObject *i_o=(obj); \ 148 { TValue *i_o=(obj); \
136 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ 149 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \
137 lua_assert(i_o->value.gc->gch.tt == LUA_TPROTO); } 150 checkliveness(L,i_o); }
138
139 151
140 152
141/*
142** for internal debug only
143*/
144#define checkconsistency(obj) \
145 lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
146 153
147 154
148#define setobj(obj1,obj2) \ 155#define setobj(L,obj1,obj2) \
149 { const TObject *o2=(obj2); TObject *o1=(obj1); \ 156 { const TValue *o2=(obj2); TValue *o1=(obj1); \
150 checkconsistency(o2); \ 157 o1->tt=o2->tt; o1->value = o2->value; \
151 o1->tt=o2->tt; o1->value = o2->value; } 158 checkliveness(L,o1); }
152 159
153 160
154/* 161/*
@@ -177,7 +184,7 @@ typedef struct lua_TObject {
177 184
178 185
179 186
180typedef TObject *StkId; /* index to stack elements */ 187typedef TValue *StkId; /* index to stack elements */
181 188
182 189
183/* 190/*
@@ -216,7 +223,7 @@ typedef union Udata {
216*/ 223*/
217typedef struct Proto { 224typedef struct Proto {
218 CommonHeader; 225 CommonHeader;
219 TObject *k; /* constants used by the function */ 226 TValue *k; /* constants used by the function */
220 Instruction *code; 227 Instruction *code;
221 struct Proto **p; /* functions defined inside the function */ 228 struct Proto **p; /* functions defined inside the function */
222 int *lineinfo; /* map from opcodes to source lines */ 229 int *lineinfo; /* map from opcodes to source lines */
@@ -253,8 +260,8 @@ typedef struct LocVar {
253typedef struct UpVal { 260typedef struct UpVal {
254 CommonHeader; 261 CommonHeader;
255 GCObject *gclist; 262 GCObject *gclist;
256 TObject *v; /* points to stack or to its own value */ 263 TValue *v; /* points to stack or to its own value */
257 TObject value; /* the value (when closed) */ 264 TValue value; /* the value (when closed) */
258} UpVal; 265} UpVal;
259 266
260 267
@@ -268,14 +275,14 @@ typedef struct UpVal {
268typedef struct CClosure { 275typedef struct CClosure {
269 ClosureHeader; 276 ClosureHeader;
270 lua_CFunction f; 277 lua_CFunction f;
271 TObject upvalue[1]; 278 TValue upvalue[1];
272} CClosure; 279} CClosure;
273 280
274 281
275typedef struct LClosure { 282typedef struct LClosure {
276 ClosureHeader; 283 ClosureHeader;
277 struct Proto *p; 284 struct Proto *p;
278 TObject g; /* global table for this closure */ 285 TValue g; /* global table for this closure */
279 UpVal *upvals[1]; 286 UpVal *upvals[1];
280} LClosure; 287} LClosure;
281 288
@@ -295,8 +302,8 @@ typedef union Closure {
295*/ 302*/
296 303
297typedef struct Node { 304typedef struct Node {
298 TObject i_key; 305 TValue i_key;
299 TObject i_val; 306 TValue i_val;
300 struct Node *next; /* for chaining */ 307 struct Node *next; /* for chaining */
301} Node; 308} Node;
302 309
@@ -306,7 +313,7 @@ typedef struct Table {
306 lu_byte flags; /* 1<<p means tagmethod(p) is not present */ 313 lu_byte flags; /* 1<<p means tagmethod(p) is not present */
307 lu_byte lsizenode; /* log2 of size of `node' array */ 314 lu_byte lsizenode; /* log2 of size of `node' array */
308 struct Table *metatable; 315 struct Table *metatable;
309 TObject *array; /* array part */ 316 TValue *array; /* array part */
310 Node *node; 317 Node *node;
311 Node *firstfree; /* this position is free; all positions after it are full */ 318 Node *firstfree; /* this position is free; all positions after it are full */
312 GCObject *gclist; 319 GCObject *gclist;
@@ -327,13 +334,13 @@ typedef struct Table {
327 334
328 335
329 336
330extern const TObject luaO_nilobject; 337extern const TValue luaO_nilobject;
331 338
332int luaO_log2 (unsigned int x); 339int luaO_log2 (unsigned int x);
333int luaO_int2fb (unsigned int x); 340int luaO_int2fb (unsigned int x);
334#define fb2int(x) (((x) & 7) << ((x) >> 3)) 341#define fb2int(x) (((x) & 7) << ((x) >> 3))
335 342
336int luaO_rawequalObj (const TObject *t1, const TObject *t2); 343int luaO_rawequalObj (const TValue *t1, const TValue *t2);
337int luaO_str2d (const char *s, lua_Number *result); 344int luaO_str2d (const char *s, lua_Number *result);
338 345
339const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp); 346const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp);
diff --git a/lparser.c b/lparser.c
index bf2b7e08..42fde44c 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.221 2003/10/09 17:56:23 roberto Exp roberto $ 2** $Id: lparser.c,v 1.222 2003/12/09 16:56:11 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*/
@@ -340,9 +340,9 @@ static void open_func (LexState *ls, FuncState *fs) {
340 f->maxstacksize = 2; /* registers 0/1 are always valid */ 340 f->maxstacksize = 2; /* registers 0/1 are always valid */
341 fs->h = luaH_new(L, 0, 0); 341 fs->h = luaH_new(L, 0, 0);
342 /* anchor table of constants and prototype (to avoid being collected) */ 342 /* anchor table of constants and prototype (to avoid being collected) */
343 sethvalue2s(L->top, fs->h); 343 sethvalue2s(L, L->top, fs->h);
344 incr_top(L); 344 incr_top(L);
345 setptvalue2s(L->top, f); 345 setptvalue2s(L, L->top, f);
346 incr_top(L); 346 incr_top(L);
347} 347}
348 348
@@ -357,7 +357,7 @@ static void close_func (LexState *ls) {
357 f->sizecode = fs->pc; 357 f->sizecode = fs->pc;
358 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); 358 luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
359 f->sizelineinfo = fs->pc; 359 f->sizelineinfo = fs->pc;
360 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject); 360 luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
361 f->sizek = fs->nk; 361 f->sizek = fs->nk;
362 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); 362 luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
363 f->sizep = fs->np; 363 f->sizep = fs->np;
diff --git a/lstate.c b/lstate.c
index e59f1a18..913b42d4 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.133 2003/12/04 17:22:42 roberto Exp roberto $ 2** $Id: lstate.c,v 1.134 2003/12/04 18:52:23 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*/
@@ -50,7 +50,7 @@ typedef struct LG {
50 50
51 51
52static void stack_init (lua_State *L1, lua_State *L) { 52static void stack_init (lua_State *L1, lua_State *L) {
53 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TObject); 53 L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
54 L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; 54 L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
55 L1->top = L1->stack; 55 L1->top = L1->stack;
56 L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; 56 L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
@@ -66,7 +66,7 @@ static void stack_init (lua_State *L1, lua_State *L) {
66 66
67static void freestack (lua_State *L, lua_State *L1) { 67static void freestack (lua_State *L, lua_State *L1) {
68 luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); 68 luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
69 luaM_freearray(L, L1->stack, L1->stacksize, TObject); 69 luaM_freearray(L, L1->stack, L1->stacksize, TValue);
70} 70}
71 71
72 72
@@ -79,12 +79,12 @@ static void f_luaopen (lua_State *L, void *ud) {
79 u = cast(Udata *, luaM_malloc(L, sizeudata(0))); 79 u = cast(Udata *, luaM_malloc(L, sizeudata(0)));
80 u->uv.len = 0; 80 u->uv.len = 0;
81 u->uv.metatable = NULL; 81 u->uv.metatable = NULL;
82 G(L)->firstudata = valtogco(u); 82 G(L)->firstudata = obj2gco(u);
83 luaC_link(L, valtogco(u), LUA_TUSERDATA); 83 luaC_link(L, obj2gco(u), LUA_TUSERDATA);
84 setbit(u->uv.marked, FIXEDBIT); 84 setbit(u->uv.marked, FIXEDBIT);
85 stack_init(L, L); /* init stack */ 85 stack_init(L, L); /* init stack */
86 sethvalue(gt(L), luaH_new(L, 0, 4)); /* table of globals */ 86 sethvalue(L, gt(L), luaH_new(L, 0, 4)); /* table of globals */
87 sethvalue(registry(L), luaH_new(L, 4, 4)); /* registry */ 87 sethvalue(L, registry(L), luaH_new(L, 4, 4)); /* registry */
88 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 88 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
89 luaT_init(L); 89 luaT_init(L);
90 luaX_init(L); 90 luaX_init(L);
@@ -127,11 +127,12 @@ static void close_state (lua_State *L) {
127 127
128lua_State *luaE_newthread (lua_State *L) { 128lua_State *luaE_newthread (lua_State *L) {
129 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); 129 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
130 luaC_link(L, valtogco(L1), LUA_TTHREAD); 130 luaC_link(L, obj2gco(L1), LUA_TTHREAD);
131 preinit_state(L1); 131 preinit_state(L1);
132 L1->l_G = L->l_G; 132 L1->l_G = L->l_G;
133 stack_init(L1, L); /* init stack */ 133 stack_init(L1, L); /* init stack */
134 setobj2n(gt(L1), gt(L)); /* share table of globals */ 134 setobj2n(L, gt(L1), gt(L)); /* share table of globals */
135 lua_assert(iswhite(obj2gco(L1)));
135 return L1; 136 return L1;
136} 137}
137 138
diff --git a/lstate.h b/lstate.h
index 4a3ea577..66db36ae 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.118 2003/12/04 17:22:42 roberto Exp roberto $ 2** $Id: lstate.h,v 1.119 2003/12/04 18:52:23 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*/
@@ -111,7 +111,7 @@ typedef struct global_State {
111 lu_mem GCthreshold; 111 lu_mem GCthreshold;
112 lu_mem nblocks; /* number of `bytes' currently allocated */ 112 lu_mem nblocks; /* number of `bytes' currently allocated */
113 lua_CFunction panic; /* to be called in unprotected errors */ 113 lua_CFunction panic; /* to be called in unprotected errors */
114 TObject _registry; 114 TValue _registry;
115 struct lua_State *mainthread; 115 struct lua_State *mainthread;
116 Node dummynode[1]; /* common node array for all empty tables */ 116 Node dummynode[1]; /* common node array for all empty tables */
117 TString *tmname[TM_N]; /* array with tag-method names */ 117 TString *tmname[TM_N]; /* array with tag-method names */
@@ -140,7 +140,7 @@ struct lua_State {
140 int basehookcount; 140 int basehookcount;
141 int hookcount; 141 int hookcount;
142 lua_Hook hook; 142 lua_Hook hook;
143 TObject _gt; /* table of globals */ 143 TValue _gt; /* table of globals */
144 GCObject *openupval; /* list of open upvalues in this stack */ 144 GCObject *openupval; /* list of open upvalues in this stack */
145 GCObject *gclist; 145 GCObject *gclist;
146 struct lua_longjmp *errorJmp; /* current error recover point */ 146 struct lua_longjmp *errorJmp; /* current error recover point */
@@ -167,18 +167,20 @@ union GCObject {
167 167
168 168
169/* macros to convert a GCObject into a specific value */ 169/* macros to convert a GCObject into a specific value */
170#define gcotots(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) 170#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
171#define gcotou(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) 171#define gco2ts(o) (&rawgco2ts(o)->tsv)
172#define gcotocl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) 172#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
173#define gcotoh(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) 173#define gco2u(o) (&rawgco2u(o)->uv)
174#define gcotop(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) 174#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
175#define gcotouv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 175#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
176#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
177#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
176#define ngcotouv(o) \ 178#define ngcotouv(o) \
177 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 179 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
178#define gcototh(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) 180#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
179 181
180/* macro to convert any value into a GCObject */ 182/* macro to convert any Lua object into a GCObject */
181#define valtogco(v) (cast(GCObject *, (v))) 183#define obj2gco(v) (cast(GCObject *, (v)))
182 184
183 185
184lua_State *luaE_newthread (lua_State *L); 186lua_State *luaE_newthread (lua_State *L);
diff --git a/lstring.c b/lstring.c
index 203c4c98..8de7d2b3 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.84 2003/12/04 17:22:42 roberto Exp roberto $ 2** $Id: lstring.c,v 1.85 2003/12/09 16:56:11 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -37,7 +37,7 @@ void luaS_resize (lua_State *L, int newsize) {
37 GCObject *p = tb->hash[i]; 37 GCObject *p = tb->hash[i];
38 while (p) { /* for each node in the list */ 38 while (p) { /* for each node in the list */
39 GCObject *next = p->gch.next; /* save next */ 39 GCObject *next = p->gch.next; /* save next */
40 unsigned int h = gcotots(p)->tsv.hash; 40 unsigned int h = gco2ts(p)->hash;
41 int h1 = lmod(h, newsize); /* new position */ 41 int h1 = lmod(h, newsize); /* new position */
42 lua_assert(cast(int, h%newsize) == lmod(h, newsize)); 42 lua_assert(cast(int, h%newsize) == lmod(h, newsize));
43 p->gch.next = newhash[h1]; /* chain it */ 43 p->gch.next = newhash[h1]; /* chain it */
@@ -65,7 +65,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
65 tb = &G(L)->strt; 65 tb = &G(L)->strt;
66 h = lmod(h, tb->size); 66 h = lmod(h, tb->size);
67 ts->tsv.next = tb->hash[h]; /* chain new entry */ 67 ts->tsv.next = tb->hash[h]; /* chain new entry */
68 tb->hash[h] = valtogco(ts); 68 tb->hash[h] = obj2gco(ts);
69 tb->nuse++; 69 tb->nuse++;
70 if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) 70 if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
71 luaS_resize(L, tb->size*2); /* too crowded */ 71 luaS_resize(L, tb->size*2); /* too crowded */
@@ -83,7 +83,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
83 for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; 83 for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
84 o != NULL; 84 o != NULL;
85 o = o->gch.next) { 85 o = o->gch.next) {
86 TString *ts = gcotots(o); 86 TString *ts = rawgco2ts(o);
87 if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { 87 if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
88 /* string may be dead */ 88 /* string may be dead */
89 if (isdead(G(L), o)) changewhite(o); 89 if (isdead(G(L), o)) changewhite(o);
@@ -103,7 +103,7 @@ Udata *luaS_newudata (lua_State *L, size_t s) {
103 u->uv.metatable = NULL; 103 u->uv.metatable = NULL;
104 /* chain it on udata list */ 104 /* chain it on udata list */
105 u->uv.next = G(L)->firstudata->uv.next; 105 u->uv.next = G(L)->firstudata->uv.next;
106 G(L)->firstudata->uv.next = valtogco(u); 106 G(L)->firstudata->uv.next = obj2gco(u);
107 return u; 107 return u;
108} 108}
109 109
diff --git a/ltable.c b/ltable.c
index b0db3bce..797690b4 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.137 2003/12/01 18:22:56 roberto Exp roberto $ 2** $Id: ltable.c,v 1.138 2003/12/09 16:56:11 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -91,12 +91,12 @@ static Node *hashnum (const Table *t, lua_Number n) {
91** returns the `main' position of an element in a table (that is, the index 91** returns the `main' position of an element in a table (that is, the index
92** of its hash value) 92** of its hash value)
93*/ 93*/
94Node *luaH_mainposition (const Table *t, const TObject *key) { 94Node *luaH_mainposition (const Table *t, const TValue *key) {
95 switch (ttype(key)) { 95 switch (ttype(key)) {
96 case LUA_TNUMBER: 96 case LUA_TNUMBER:
97 return hashnum(t, nvalue(key)); 97 return hashnum(t, nvalue(key));
98 case LUA_TSTRING: 98 case LUA_TSTRING:
99 return hashstr(t, tsvalue(key)); 99 return hashstr(t, rawtsvalue(key));
100 case LUA_TBOOLEAN: 100 case LUA_TBOOLEAN:
101 return hashboolean(t, bvalue(key)); 101 return hashboolean(t, bvalue(key));
102 case LUA_TLIGHTUSERDATA: 102 case LUA_TLIGHTUSERDATA:
@@ -111,7 +111,7 @@ Node *luaH_mainposition (const Table *t, const TObject *key) {
111** returns the index for `key' if `key' is an appropriate key to live in 111** returns the index for `key' if `key' is an appropriate key to live in
112** the array part of the table, -1 otherwise. 112** the array part of the table, -1 otherwise.
113*/ 113*/
114static int arrayindex (const TObject *key, lua_Number lim) { 114static int arrayindex (const TValue *key, lua_Number lim) {
115 if (ttisnumber(key)) { 115 if (ttisnumber(key)) {
116 lua_Number n = nvalue(key); 116 lua_Number n = nvalue(key);
117 int k; 117 int k;
@@ -137,7 +137,7 @@ static int luaH_index (lua_State *L, Table *t, StkId key) {
137 return i-1; /* yes; that's the index (corrected to C) */ 137 return i-1; /* yes; that's the index (corrected to C) */
138 } 138 }
139 else { 139 else {
140 const TObject *v = luaH_get(t, key); 140 const TValue *v = luaH_get(t, key);
141 if (v == &luaO_nilobject) 141 if (v == &luaO_nilobject)
142 luaG_runerror(L, "invalid key for `next'"); 142 luaG_runerror(L, "invalid key for `next'");
143 i = cast(int, (cast(const lu_byte *, v) - 143 i = cast(int, (cast(const lu_byte *, v) -
@@ -152,14 +152,14 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
152 for (i++; i < t->sizearray; i++) { /* try first array part */ 152 for (i++; i < t->sizearray; i++) { /* try first array part */
153 if (!ttisnil(&t->array[i])) { /* a non-nil value? */ 153 if (!ttisnil(&t->array[i])) { /* a non-nil value? */
154 setnvalue(key, cast(lua_Number, i+1)); 154 setnvalue(key, cast(lua_Number, i+1));
155 setobj2s(key+1, &t->array[i]); 155 setobj2s(L, key+1, &t->array[i]);
156 return 1; 156 return 1;
157 } 157 }
158 } 158 }
159 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */ 159 for (i -= t->sizearray; i < sizenode(t); i++) { /* then hash part */
160 if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ 160 if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */
161 setobj2s(key, gkey(gnode(t, i))); 161 setobj2s(L, key, gkey(gnode(t, i)));
162 setobj2s(key+1, gval(gnode(t, i))); 162 setobj2s(L, key+1, gval(gnode(t, i)));
163 return 1; 163 return 1;
164 } 164 }
165 } 165 }
@@ -239,7 +239,7 @@ static void numuse (const Table *t, int *narray, int *nhash) {
239 239
240static void setarrayvector (lua_State *L, Table *t, int size) { 240static void setarrayvector (lua_State *L, Table *t, int size) {
241 int i; 241 int i;
242 luaM_reallocvector(L, t->array, t->sizearray, size, TObject); 242 luaM_reallocvector(L, t->array, t->sizearray, size, TValue);
243 for (i=t->sizearray; i<size; i++) 243 for (i=t->sizearray; i<size; i++)
244 setnilvalue(&t->array[i]); 244 setnilvalue(&t->array[i]);
245 t->sizearray = size; 245 t->sizearray = size;
@@ -296,16 +296,16 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
296 /* re-insert elements from vanishing slice */ 296 /* re-insert elements from vanishing slice */
297 for (i=nasize; i<oldasize; i++) { 297 for (i=nasize; i<oldasize; i++) {
298 if (!ttisnil(&t->array[i])) 298 if (!ttisnil(&t->array[i]))
299 setobjt2t(luaH_setnum(L, t, i+1), &t->array[i]); 299 setobjt2t(L, luaH_setnum(L, t, i+1), &t->array[i]);
300 } 300 }
301 /* shrink array */ 301 /* shrink array */
302 luaM_reallocvector(L, t->array, oldasize, nasize, TObject); 302 luaM_reallocvector(L, t->array, oldasize, nasize, TValue);
303 } 303 }
304 /* re-insert elements in hash part */ 304 /* re-insert elements in hash part */
305 for (i = twoto(oldhsize) - 1; i >= 0; i--) { 305 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
306 Node *old = nold+i; 306 Node *old = nold+i;
307 if (!ttisnil(gval(old))) 307 if (!ttisnil(gval(old)))
308 setobjt2t(luaH_set(L, t, gkey(old)), gval(old)); 308 setobjt2t(L, luaH_set(L, t, gkey(old)), gval(old));
309 } 309 }
310 if (oldhsize) 310 if (oldhsize)
311 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ 311 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
@@ -327,7 +327,7 @@ static void rehash (lua_State *L, Table *t) {
327 327
328Table *luaH_new (lua_State *L, int narray, int lnhash) { 328Table *luaH_new (lua_State *L, int narray, int lnhash) {
329 Table *t = luaM_new(L, Table); 329 Table *t = luaM_new(L, Table);
330 luaC_link(L, valtogco(t), LUA_TTABLE); 330 luaC_link(L, obj2gco(t), LUA_TTABLE);
331 t->metatable = NULL; 331 t->metatable = NULL;
332 t->flags = cast(lu_byte, ~0); 332 t->flags = cast(lu_byte, ~0);
333 /* temporary values (kept only if some malloc fails) */ 333 /* temporary values (kept only if some malloc fails) */
@@ -344,7 +344,7 @@ Table *luaH_new (lua_State *L, int narray, int lnhash) {
344void luaH_free (lua_State *L, Table *t) { 344void luaH_free (lua_State *L, Table *t) {
345 if (t->lsizenode) 345 if (t->lsizenode)
346 luaM_freearray(L, t->node, sizenode(t), Node); 346 luaM_freearray(L, t->node, sizenode(t), Node);
347 luaM_freearray(L, t->array, t->sizearray, TObject); 347 luaM_freearray(L, t->array, t->sizearray, TValue);
348 luaM_freelem(L, t); 348 luaM_freelem(L, t);
349} 349}
350 350
@@ -377,8 +377,8 @@ void luaH_remove (Table *t, Node *e) {
377** put new key in its main position; otherwise (colliding node is in its main 377** put new key in its main position; otherwise (colliding node is in its main
378** position), new key goes to an empty position. 378** position), new key goes to an empty position.
379*/ 379*/
380static TObject *newkey (lua_State *L, Table *t, const TObject *key) { 380static TValue *newkey (lua_State *L, Table *t, const TValue *key) {
381 TObject *val; 381 TValue *val;
382 Node *mp = luaH_mainposition(t, key); 382 Node *mp = luaH_mainposition(t, key);
383 if (!ttisnil(gval(mp))) { /* main position is not free? */ 383 if (!ttisnil(gval(mp))) { /* main position is not free? */
384 Node *othern = luaH_mainposition(t, gkey(mp)); /* `mp' of colliding node */ 384 Node *othern = luaH_mainposition(t, gkey(mp)); /* `mp' of colliding node */
@@ -398,7 +398,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
398 mp = n; 398 mp = n;
399 } 399 }
400 } 400 }
401 setobj2t(gkey(mp), key); 401 setobj2t(L, gkey(mp), key);
402 luaC_barrier(L, t, key); 402 luaC_barrier(L, t, key);
403 lua_assert(ttisnil(gval(mp))); 403 lua_assert(ttisnil(gval(mp)));
404 for (;;) { /* correct `firstfree' */ 404 for (;;) { /* correct `firstfree' */
@@ -410,7 +410,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
410 /* no more free places; must create one */ 410 /* no more free places; must create one */
411 setbvalue(gval(mp), 0); /* avoid new key being removed */ 411 setbvalue(gval(mp), 0); /* avoid new key being removed */
412 rehash(L, t); /* grow table */ 412 rehash(L, t); /* grow table */
413 val = cast(TObject *, luaH_get(t, key)); /* get new position */ 413 val = cast(TValue *, luaH_get(t, key)); /* get new position */
414 lua_assert(ttisboolean(val)); 414 lua_assert(ttisboolean(val));
415 setnilvalue(val); 415 setnilvalue(val);
416 return val; 416 return val;
@@ -420,7 +420,7 @@ static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
420/* 420/*
421** generic search function 421** generic search function
422*/ 422*/
423static const TObject *luaH_getany (Table *t, const TObject *key) { 423static const TValue *luaH_getany (Table *t, const TValue *key) {
424 if (!ttisnil(key)) { 424 if (!ttisnil(key)) {
425 Node *n = luaH_mainposition(t, key); 425 Node *n = luaH_mainposition(t, key);
426 do { /* check whether `key' is somewhere in the chain */ 426 do { /* check whether `key' is somewhere in the chain */
@@ -435,7 +435,7 @@ static const TObject *luaH_getany (Table *t, const TObject *key) {
435/* 435/*
436** search function for integers 436** search function for integers
437*/ 437*/
438const TObject *luaH_getnum (Table *t, int key) { 438const TValue *luaH_getnum (Table *t, int key) {
439 if (1 <= key && key <= t->sizearray) 439 if (1 <= key && key <= t->sizearray)
440 return &t->array[key-1]; 440 return &t->array[key-1];
441 else { 441 else {
@@ -454,10 +454,10 @@ const TObject *luaH_getnum (Table *t, int key) {
454/* 454/*
455** search function for strings 455** search function for strings
456*/ 456*/
457const TObject *luaH_getstr (Table *t, TString *key) { 457const TValue *luaH_getstr (Table *t, TString *key) {
458 Node *n = hashstr(t, key); 458 Node *n = hashstr(t, key);
459 do { /* check whether `key' is somewhere in the chain */ 459 do { /* check whether `key' is somewhere in the chain */
460 if (ttisstring(gkey(n)) && tsvalue(gkey(n)) == key) 460 if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
461 return gval(n); /* that's it */ 461 return gval(n); /* that's it */
462 else n = n->next; 462 else n = n->next;
463 } while (n); 463 } while (n);
@@ -468,9 +468,9 @@ const TObject *luaH_getstr (Table *t, TString *key) {
468/* 468/*
469** main search function 469** main search function
470*/ 470*/
471const TObject *luaH_get (Table *t, const TObject *key) { 471const TValue *luaH_get (Table *t, const TValue *key) {
472 switch (ttype(key)) { 472 switch (ttype(key)) {
473 case LUA_TSTRING: return luaH_getstr(t, tsvalue(key)); 473 case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
474 case LUA_TNUMBER: { 474 case LUA_TNUMBER: {
475 int k; 475 int k;
476 lua_number2int(k, (nvalue(key))); 476 lua_number2int(k, (nvalue(key)));
@@ -483,11 +483,11 @@ const TObject *luaH_get (Table *t, const TObject *key) {
483} 483}
484 484
485 485
486TObject *luaH_set (lua_State *L, Table *t, const TObject *key) { 486TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
487 const TObject *p = luaH_get(t, key); 487 const TValue *p = luaH_get(t, key);
488 t->flags = 0; 488 t->flags = 0;
489 if (p != &luaO_nilobject) 489 if (p != &luaO_nilobject)
490 return cast(TObject *, p); 490 return cast(TValue *, p);
491 else { 491 else {
492 if (ttisnil(key)) luaG_runerror(L, "table index is nil"); 492 if (ttisnil(key)) luaG_runerror(L, "table index is nil");
493 else if (ttisnumber(key) && nvalue(key) != nvalue(key)) 493 else if (ttisnumber(key) && nvalue(key) != nvalue(key))
@@ -497,25 +497,25 @@ TObject *luaH_set (lua_State *L, Table *t, const TObject *key) {
497} 497}
498 498
499 499
500TObject *luaH_setnum (lua_State *L, Table *t, int key) { 500TValue *luaH_setnum (lua_State *L, Table *t, int key) {
501 const TObject *p = luaH_getnum(t, key); 501 const TValue *p = luaH_getnum(t, key);
502 if (p != &luaO_nilobject) 502 if (p != &luaO_nilobject)
503 return cast(TObject *, p); 503 return cast(TValue *, p);
504 else { 504 else {
505 TObject k; 505 TValue k;
506 setnvalue(&k, cast(lua_Number, key)); 506 setnvalue(&k, cast(lua_Number, key));
507 return newkey(L, t, &k); 507 return newkey(L, t, &k);
508 } 508 }
509} 509}
510 510
511 511
512TObject *luaH_setstr (lua_State *L, Table *t, TString *key) { 512TValue *luaH_setstr (lua_State *L, Table *t, TString *key) {
513 const TObject *p = luaH_getstr(t, key); 513 const TValue *p = luaH_getstr(t, key);
514 if (p != &luaO_nilobject) 514 if (p != &luaO_nilobject)
515 return cast(TObject *, p); 515 return cast(TValue *, p);
516 else { 516 else {
517 TObject k; 517 TValue k;
518 setsvalue(&k, key); 518 setsvalue(L, &k, key);
519 return newkey(L, t, &k); 519 return newkey(L, t, &k);
520 } 520 }
521} 521}
diff --git a/ltable.h b/ltable.h
index 5a4076bc..e953bb70 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.h,v 1.44 2003/03/18 12:50:04 roberto Exp roberto $ 2** $Id: ltable.h,v 1.45 2003/08/26 12:04:13 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,18 +15,18 @@
15#define gval(n) (&(n)->i_val) 15#define gval(n) (&(n)->i_val)
16 16
17 17
18const TObject *luaH_getnum (Table *t, int key); 18const TValue *luaH_getnum (Table *t, int key);
19TObject *luaH_setnum (lua_State *L, Table *t, int key); 19TValue *luaH_setnum (lua_State *L, Table *t, int key);
20const TObject *luaH_getstr (Table *t, TString *key); 20const TValue *luaH_getstr (Table *t, TString *key);
21TObject *luaH_setstr (lua_State *L, Table *t, TString *key); 21TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
22const TObject *luaH_get (Table *t, const TObject *key); 22const TValue *luaH_get (Table *t, const TValue *key);
23TObject *luaH_set (lua_State *L, Table *t, const TObject *key); 23TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
24Table *luaH_new (lua_State *L, int narray, int lnhash); 24Table *luaH_new (lua_State *L, int narray, int lnhash);
25void luaH_free (lua_State *L, Table *t); 25void luaH_free (lua_State *L, Table *t);
26int luaH_next (lua_State *L, Table *t, StkId key); 26int luaH_next (lua_State *L, Table *t, StkId key);
27 27
28/* exported only for debugging */ 28/* exported only for debugging */
29Node *luaH_mainposition (const Table *t, const TObject *key); 29Node *luaH_mainposition (const Table *t, const TValue *key);
30 30
31 31
32#endif 32#endif
diff --git a/ltests.c b/ltests.c
index b342b169..05093162 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.168 2003/11/05 11:59:14 roberto Exp roberto $ 2** $Id: ltests.c,v 1.169 2003/11/19 12:21:57 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*/
@@ -269,10 +269,10 @@ static int mem_query (lua_State *L) {
269static int hash_query (lua_State *L) { 269static int hash_query (lua_State *L) {
270 if (lua_isnone(L, 2)) { 270 if (lua_isnone(L, 2)) {
271 luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); 271 luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected");
272 lua_pushinteger(L, tsvalue(func_at(L, 1))->tsv.hash); 272 lua_pushinteger(L, tsvalue(func_at(L, 1))->hash);
273 } 273 }
274 else { 274 else {
275 TObject *o = func_at(L, 1); 275 TValue *o = func_at(L, 1);
276 Table *t; 276 Table *t;
277 luaL_checktype(L, 2, LUA_TTABLE); 277 luaL_checktype(L, 2, LUA_TTABLE);
278 t = hvalue(func_at(L, 2)); 278 t = hvalue(func_at(L, 2));
@@ -338,7 +338,7 @@ static int string_query (lua_State *L) {
338 GCObject *ts; 338 GCObject *ts;
339 int n = 0; 339 int n = 0;
340 for (ts = tb->hash[s]; ts; ts = ts->gch.next) { 340 for (ts = tb->hash[s]; ts; ts = ts->gch.next) {
341 setsvalue2s(L->top, gcotots(ts)); 341 setsvalue2s(L, L->top, gco2ts(ts));
342 incr_top(L); 342 incr_top(L);
343 n++; 343 n++;
344 } 344 }
diff --git a/ltests.h b/ltests.h
index 0eb64bcf..2fc73fda 100644
--- a/ltests.h
+++ b/ltests.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.h,v 1.20 2002/12/04 17:29:05 roberto Exp roberto $ 2** $Id: ltests.h,v 1.21 2003/10/02 20:31:17 roberto Exp roberto $
3** Internal Header for Debugging of the Lua Implementation 3** Internal Header for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -19,7 +19,6 @@
19#include <assert.h> 19#include <assert.h>
20#define lua_assert(c) assert(c) 20#define lua_assert(c) assert(c)
21#define check_exp(c,e) (lua_assert(c), (e)) 21#define check_exp(c,e) (lua_assert(c), (e))
22#define api_check(L, o) lua_assert(o)
23 22
24 23
25/* to avoid warnings, and to make sure value is really unused */ 24/* to avoid warnings, and to make sure value is really unused */
diff --git a/ltm.c b/ltm.c
index b8fbb1f9..230fbba6 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.106 2003/04/03 13:35:34 roberto Exp roberto $ 2** $Id: ltm.c,v 1.107 2003/12/01 18:22:56 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -45,8 +45,8 @@ void luaT_init (lua_State *L) {
45** function to be used with macro "fasttm": optimized for absence of 45** function to be used with macro "fasttm": optimized for absence of
46** tag methods 46** tag methods
47*/ 47*/
48const TObject *luaT_gettm (Table *events, TMS event, TString *ename) { 48const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
49 const TObject *tm = luaH_getstr(events, ename); 49 const TValue *tm = luaH_getstr(events, ename);
50 lua_assert(event <= TM_EQ); 50 lua_assert(event <= TM_EQ);
51 if (ttisnil(tm)) { /* no tag method? */ 51 if (ttisnil(tm)) { /* no tag method? */
52 events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */ 52 events->flags |= cast(lu_byte, 1u<<event); /* cache this fact */
@@ -56,14 +56,14 @@ const TObject *luaT_gettm (Table *events, TMS event, TString *ename) {
56} 56}
57 57
58 58
59const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event) { 59const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
60 Table *mt; 60 Table *mt;
61 switch (ttype(o)) { 61 switch (ttype(o)) {
62 case LUA_TTABLE: 62 case LUA_TTABLE:
63 mt = hvalue(o)->metatable; 63 mt = hvalue(o)->metatable;
64 break; 64 break;
65 case LUA_TUSERDATA: 65 case LUA_TUSERDATA:
66 mt = uvalue(o)->uv.metatable; 66 mt = uvalue(o)->metatable;
67 break; 67 break;
68 default: 68 default:
69 mt = NULL; 69 mt = NULL;
diff --git a/ltm.h b/ltm.h
index d40bf6c5..6ae743f0 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 1.41 2002/11/14 11:51:50 roberto Exp roberto $ 2** $Id: ltm.h,v 1.42 2003/12/01 18:22:56 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -42,8 +42,8 @@ typedef enum {
42#define fasttm(l,et,e) gfasttm(G(l), et, e) 42#define fasttm(l,et,e) gfasttm(G(l), et, e)
43 43
44 44
45const TObject *luaT_gettm (Table *events, TMS event, TString *ename); 45const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
46const TObject *luaT_gettmbyobj (lua_State *L, const TObject *o, TMS event); 46const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event);
47void luaT_init (lua_State *L); 47void luaT_init (lua_State *L);
48 48
49extern const char *const luaT_typenames[]; 49extern const char *const luaT_typenames[];
diff --git a/lundump.c b/lundump.c
index 0777dc0f..10508ed4 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.63 2003/08/25 19:51:54 roberto Exp roberto $ 2** $Id: lundump.c,v 1.64 2003/08/27 21:01:44 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*/
@@ -158,13 +158,14 @@ static Proto* LoadFunction (LoadState* S, TString* p);
158static void LoadConstants (LoadState* S, Proto* f) 158static void LoadConstants (LoadState* S, Proto* f)
159{ 159{
160 int i,n; 160 int i,n;
161 lua_State *L=S->L;
161 n=LoadInt(S); 162 n=LoadInt(S);
162 f->k=luaM_newvector(S->L,n,TObject); 163 f->k=luaM_newvector(L,n,TValue);
163 f->sizek=n; 164 f->sizek=n;
164 for (i=0; i<n; i++) setnilvalue(&f->k[i]); 165 for (i=0; i<n; i++) setnilvalue(&f->k[i]);
165 for (i=0; i<n; i++) 166 for (i=0; i<n; i++)
166 { 167 {
167 TObject* o=&f->k[i]; 168 TValue* o=&f->k[i];
168 int t=LoadByte(S); 169 int t=LoadByte(S);
169 switch (t) 170 switch (t)
170 { 171 {
@@ -172,18 +173,18 @@ static void LoadConstants (LoadState* S, Proto* f)
172 setnvalue(o,LoadNumber(S)); 173 setnvalue(o,LoadNumber(S));
173 break; 174 break;
174 case LUA_TSTRING: 175 case LUA_TSTRING:
175 setsvalue2n(o,LoadString(S)); 176 setsvalue2n(L, o,LoadString(S));
176 break; 177 break;
177 case LUA_TNIL: 178 case LUA_TNIL:
178 setnilvalue(o); 179 setnilvalue(o);
179 break; 180 break;
180 default: 181 default:
181 luaG_runerror(S->L,"bad constant type (%d) in %s",t,S->name); 182 luaG_runerror(L,"bad constant type (%d) in %s",t,S->name);
182 break; 183 break;
183 } 184 }
184 } 185 }
185 n=LoadInt(S); 186 n=LoadInt(S);
186 f->p=luaM_newvector(S->L,n,Proto*); 187 f->p=luaM_newvector(L,n,Proto*);
187 f->sizep=n; 188 f->sizep=n;
188 for (i=0; i<n; i++) f->p[i]=NULL; 189 for (i=0; i<n; i++) f->p[i]=NULL;
189 for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source); 190 for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
@@ -191,9 +192,10 @@ static void LoadConstants (LoadState* S, Proto* f)
191 192
192static Proto* LoadFunction (LoadState* S, TString* p) 193static Proto* LoadFunction (LoadState* S, TString* p)
193{ 194{
194 Proto* f=luaF_newproto(S->L); 195 lua_State *L=S->L;
195 setptvalue2s(S->L->top, f); 196 Proto* f=luaF_newproto(L);
196 incr_top(S->L); 197 setptvalue2s(L, L->top, f);
198 incr_top(L);
197 f->source=LoadString(S); if (f->source==NULL) f->source=p; 199 f->source=LoadString(S); if (f->source==NULL) f->source=p;
198 f->lineDefined=LoadInt(S); 200 f->lineDefined=LoadInt(S);
199 f->nups=LoadByte(S); 201 f->nups=LoadByte(S);
@@ -206,9 +208,9 @@ static Proto* LoadFunction (LoadState* S, TString* p)
206 LoadConstants(S,f); 208 LoadConstants(S,f);
207 LoadCode(S,f); 209 LoadCode(S,f);
208#ifndef TRUST_BINARIES 210#ifndef TRUST_BINARIES
209 if (!luaG_checkcode(f)) luaG_runerror(S->L,"bad code in %s",S->name); 211 if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in %s",S->name);
210#endif 212#endif
211 S->L->top--; 213 L->top--;
212 return f; 214 return f;
213} 215}
214 216
diff --git a/lvm.c b/lvm.c
index 29c27f0f..8ebf102a 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.290 2003/10/27 19:14:31 roberto Exp roberto $ 2** $Id: lvm.c,v 1.291 2003/12/09 16:56:11 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*/
@@ -40,7 +40,7 @@
40#define MAXTAGLOOP 100 40#define MAXTAGLOOP 100
41 41
42 42
43const TObject *luaV_tonumber (const TObject *obj, TObject *n) { 43const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
44 lua_Number num; 44 lua_Number num;
45 if (ttisnumber(obj)) return obj; 45 if (ttisnumber(obj)) return obj;
46 if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { 46 if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
@@ -58,7 +58,7 @@ int luaV_tostring (lua_State *L, StkId obj) {
58 else { 58 else {
59 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ 59 char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
60 lua_number2str(s, nvalue(obj)); 60 lua_number2str(s, nvalue(obj));
61 setsvalue2s(obj, luaS_new(L, s)); 61 setsvalue2s(L, obj, luaS_new(L, s));
62 return 1; 62 return 1;
63 } 63 }
64} 64}
@@ -88,11 +88,11 @@ static void traceexec (lua_State *L, const Instruction *pc) {
88} 88}
89 89
90 90
91static void prepTMcall (lua_State *L, const TObject *f, 91static void prepTMcall (lua_State *L, const TValue *f,
92 const TObject *p1, const TObject *p2) { 92 const TValue *p1, const TValue *p2) {
93 setobj2s(L->top, f); /* push function */ 93 setobj2s(L, L->top, f); /* push function */
94 setobj2s(L->top+1, p1); /* 1st argument */ 94 setobj2s(L, L->top+1, p1); /* 1st argument */
95 setobj2s(L->top+2, p2); /* 2nd argument */ 95 setobj2s(L, L->top+2, p2); /* 2nd argument */
96} 96}
97 97
98 98
@@ -103,7 +103,7 @@ static void callTMres (lua_State *L, StkId res) {
103 luaD_call(L, L->top - 3, 1); 103 luaD_call(L, L->top - 3, 1);
104 res = restorestack(L, result); 104 res = restorestack(L, result);
105 L->top--; 105 L->top--;
106 setobjs2s(res, L->top); 106 setobjs2s(L, res, L->top);
107} 107}
108 108
109 109
@@ -115,16 +115,16 @@ static void callTM (lua_State *L) {
115} 115}
116 116
117 117
118void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId val) { 118void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
119 int loop; 119 int loop;
120 for (loop = 0; loop < MAXTAGLOOP; loop++) { 120 for (loop = 0; loop < MAXTAGLOOP; loop++) {
121 const TObject *tm; 121 const TValue *tm;
122 if (ttistable(t)) { /* `t' is a table? */ 122 if (ttistable(t)) { /* `t' is a table? */
123 Table *h = hvalue(t); 123 Table *h = hvalue(t);
124 const TObject *res = luaH_get(h, key); /* do a primitive set */ 124 const TValue *res = luaH_get(h, key); /* do a primitive set */
125 if (!ttisnil(res) || /* result is no nil? */ 125 if (!ttisnil(res) || /* result is no nil? */
126 (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ 126 (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
127 setobj2s(val, res); 127 setobj2s(L, val, res);
128 return; 128 return;
129 } 129 }
130 /* else will try the tag method */ 130 /* else will try the tag method */
@@ -142,16 +142,16 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId val) {
142} 142}
143 143
144 144
145void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) { 145void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
146 int loop; 146 int loop;
147 for (loop = 0; loop < MAXTAGLOOP; loop++) { 147 for (loop = 0; loop < MAXTAGLOOP; loop++) {
148 const TObject *tm; 148 const TValue *tm;
149 if (ttistable(t)) { /* `t' is a table? */ 149 if (ttistable(t)) { /* `t' is a table? */
150 Table *h = hvalue(t); 150 Table *h = hvalue(t);
151 TObject *oldval = luaH_set(L, h, key); /* do a primitive set */ 151 TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
152 if (!ttisnil(oldval) || /* result is no nil? */ 152 if (!ttisnil(oldval) || /* result is no nil? */
153 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ 153 (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
154 setobj2t(oldval, val); 154 setobj2t(L, oldval, val);
155 luaC_barrier(L, h, val); 155 luaC_barrier(L, h, val);
156 return; 156 return;
157 } 157 }
@@ -161,7 +161,7 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
161 luaG_typeerror(L, t, "index"); 161 luaG_typeerror(L, t, "index");
162 if (ttisfunction(tm)) { 162 if (ttisfunction(tm)) {
163 prepTMcall(L, tm, t, key); 163 prepTMcall(L, tm, t, key);
164 setobj2s(L->top+3, val); /* 3th argument */ 164 setobj2s(L, L->top+3, val); /* 3th argument */
165 callTM(L); 165 callTM(L);
166 return; 166 return;
167 } 167 }
@@ -171,9 +171,9 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
171} 171}
172 172
173 173
174static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2, 174static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
175 StkId res, TMS event) { 175 StkId res, TMS event) {
176 const TObject *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 176 const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
177 if (ttisnil(tm)) 177 if (ttisnil(tm))
178 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 178 tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
179 if (!ttisfunction(tm)) return 0; 179 if (!ttisfunction(tm)) return 0;
@@ -183,10 +183,10 @@ static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2,
183} 183}
184 184
185 185
186static const TObject *get_compTM (lua_State *L, Table *mt1, Table *mt2, 186static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,
187 TMS event) { 187 TMS event) {
188 const TObject *tm1 = fasttm(L, mt1, event); 188 const TValue *tm1 = fasttm(L, mt1, event);
189 const TObject *tm2; 189 const TValue *tm2;
190 if (tm1 == NULL) return NULL; /* no metamethod */ 190 if (tm1 == NULL) return NULL; /* no metamethod */
191 if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ 191 if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
192 tm2 = fasttm(L, mt2, event); 192 tm2 = fasttm(L, mt2, event);
@@ -197,10 +197,10 @@ static const TObject *get_compTM (lua_State *L, Table *mt1, Table *mt2,
197} 197}
198 198
199 199
200static int call_orderTM (lua_State *L, const TObject *p1, const TObject *p2, 200static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
201 TMS event) { 201 TMS event) {
202 const TObject *tm1 = luaT_gettmbyobj(L, p1, event); 202 const TValue *tm1 = luaT_gettmbyobj(L, p1, event);
203 const TObject *tm2; 203 const TValue *tm2;
204 if (ttisnil(tm1)) return -1; /* no metamethod? */ 204 if (ttisnil(tm1)) return -1; /* no metamethod? */
205 tm2 = luaT_gettmbyobj(L, p2, event); 205 tm2 = luaT_gettmbyobj(L, p2, event);
206 if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */ 206 if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */
@@ -233,28 +233,28 @@ static int luaV_strcmp (const TString *ls, const TString *rs) {
233} 233}
234 234
235 235
236int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r) { 236int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
237 int res; 237 int res;
238 if (ttype(l) != ttype(r)) 238 if (ttype(l) != ttype(r))
239 return luaG_ordererror(L, l, r); 239 return luaG_ordererror(L, l, r);
240 else if (ttisnumber(l)) 240 else if (ttisnumber(l))
241 return nvalue(l) < nvalue(r); 241 return nvalue(l) < nvalue(r);
242 else if (ttisstring(l)) 242 else if (ttisstring(l))
243 return luaV_strcmp(tsvalue(l), tsvalue(r)) < 0; 243 return luaV_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
244 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1) 244 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
245 return res; 245 return res;
246 return luaG_ordererror(L, l, r); 246 return luaG_ordererror(L, l, r);
247} 247}
248 248
249 249
250static int luaV_lessequal (lua_State *L, const TObject *l, const TObject *r) { 250static int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
251 int res; 251 int res;
252 if (ttype(l) != ttype(r)) 252 if (ttype(l) != ttype(r))
253 return luaG_ordererror(L, l, r); 253 return luaG_ordererror(L, l, r);
254 else if (ttisnumber(l)) 254 else if (ttisnumber(l))
255 return nvalue(l) <= nvalue(r); 255 return nvalue(l) <= nvalue(r);
256 else if (ttisstring(l)) 256 else if (ttisstring(l))
257 return luaV_strcmp(tsvalue(l), tsvalue(r)) <= 0; 257 return luaV_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
258 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */ 258 else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
259 return res; 259 return res;
260 else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */ 260 else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
@@ -263,8 +263,8 @@ static int luaV_lessequal (lua_State *L, const TObject *l, const TObject *r) {
263} 263}
264 264
265 265
266int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2) { 266int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) {
267 const TObject *tm; 267 const TValue *tm;
268 lua_assert(ttype(t1) == ttype(t2)); 268 lua_assert(ttype(t1) == ttype(t2));
269 switch (ttype(t1)) { 269 switch (ttype(t1)) {
270 case LUA_TNIL: return 1; 270 case LUA_TNIL: return 1;
@@ -273,7 +273,7 @@ int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2) {
273 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); 273 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
274 case LUA_TUSERDATA: { 274 case LUA_TUSERDATA: {
275 if (uvalue(t1) == uvalue(t2)) return 1; 275 if (uvalue(t1) == uvalue(t2)) return 1;
276 tm = get_compTM(L, uvalue(t1)->uv.metatable, uvalue(t2)->uv.metatable, 276 tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,
277 TM_EQ); 277 TM_EQ);
278 break; /* will try TM */ 278 break; /* will try TM */
279 } 279 }
@@ -298,25 +298,25 @@ void luaV_concat (lua_State *L, int total, int last) {
298 if (!tostring(L, top-2) || !tostring(L, top-1)) { 298 if (!tostring(L, top-2) || !tostring(L, top-1)) {
299 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) 299 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
300 luaG_concaterror(L, top-2, top-1); 300 luaG_concaterror(L, top-2, top-1);
301 } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */ 301 } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
302 /* at least two string values; get as many as possible */ 302 /* at least two string values; get as many as possible */
303 lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) + 303 lu_mem tl = cast(lu_mem, tsvalue(top-1)->len) +
304 cast(lu_mem, tsvalue(top-2)->tsv.len); 304 cast(lu_mem, tsvalue(top-2)->len);
305 char *buffer; 305 char *buffer;
306 int i; 306 int i;
307 while (n < total && tostring(L, top-n-1)) { /* collect total length */ 307 while (n < total && tostring(L, top-n-1)) { /* collect total length */
308 tl += tsvalue(top-n-1)->tsv.len; 308 tl += tsvalue(top-n-1)->len;
309 n++; 309 n++;
310 } 310 }
311 if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow"); 311 if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
312 buffer = luaZ_openspace(L, &G(L)->buff, tl); 312 buffer = luaZ_openspace(L, &G(L)->buff, tl);
313 tl = 0; 313 tl = 0;
314 for (i=n; i>0; i--) { /* concat all strings */ 314 for (i=n; i>0; i--) { /* concat all strings */
315 size_t l = tsvalue(top-i)->tsv.len; 315 size_t l = tsvalue(top-i)->len;
316 memcpy(buffer+tl, svalue(top-i), l); 316 memcpy(buffer+tl, svalue(top-i), l);
317 tl += l; 317 tl += l;
318 } 318 }
319 setsvalue2s(top-n, luaS_newlstr(L, buffer, tl)); 319 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
320 } 320 }
321 total -= n-1; /* got `n' strings to create 1 new */ 321 total -= n-1; /* got `n' strings to create 1 new */
322 last -= n-1; 322 last -= n-1;
@@ -324,10 +324,10 @@ void luaV_concat (lua_State *L, int total, int last) {
324} 324}
325 325
326 326
327static StkId Arith (lua_State *L, StkId ra, const TObject *rb, 327static StkId Arith (lua_State *L, StkId ra, const TValue *rb,
328 const TObject *rc, TMS op, const Instruction *pc) { 328 const TValue *rc, TMS op, const Instruction *pc) {
329 TObject tempb, tempc; 329 TValue tempb, tempc;
330 const TObject *b, *c; 330 const TValue *b, *c;
331 L->ci->u.l.savedpc = pc; 331 L->ci->u.l.savedpc = pc;
332 if ((b = luaV_tonumber(rb, &tempb)) != NULL && 332 if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
333 (c = luaV_tonumber(rc, &tempc)) != NULL) { 333 (c = luaV_tonumber(rc, &tempc)) != NULL) {
@@ -337,7 +337,7 @@ static StkId Arith (lua_State *L, StkId ra, const TObject *rb,
337 case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break; 337 case TM_MUL: setnvalue(ra, nvalue(b) * nvalue(c)); break;
338 case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break; 338 case TM_DIV: setnvalue(ra, nvalue(b) / nvalue(c)); break;
339 case TM_POW: { 339 case TM_POW: {
340 const TObject *f = luaH_getstr(hvalue(gt(L)), G(L)->tmname[TM_POW]); 340 const TValue *f = luaH_getstr(hvalue(gt(L)), G(L)->tmname[TM_POW]);
341 if (!ttisfunction(f)) 341 if (!ttisfunction(f))
342 luaG_runerror(L, "`__pow' (`^' operator) is not a function"); 342 luaG_runerror(L, "`__pow' (`^' operator) is not a function");
343 prepTMcall(L, f, b, c); 343 prepTMcall(L, f, b, c);
@@ -376,7 +376,7 @@ static StkId Arith (lua_State *L, StkId ra, const TObject *rb,
376 376
377StkId luaV_execute (lua_State *L, int nexeccalls) { 377StkId luaV_execute (lua_State *L, int nexeccalls) {
378 LClosure *cl; 378 LClosure *cl;
379 TObject *k; 379 TValue *k;
380 StkId base; 380 StkId base;
381 const Instruction *pc; 381 const Instruction *pc;
382 callentry: /* entry point when calling new functions */ 382 callentry: /* entry point when calling new functions */
@@ -409,11 +409,11 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
409 GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO); 409 GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO);
410 switch (GET_OPCODE(i)) { 410 switch (GET_OPCODE(i)) {
411 case OP_MOVE: { 411 case OP_MOVE: {
412 setobjs2s(ra, RB(i)); 412 setobjs2s(L, ra, RB(i));
413 break; 413 break;
414 } 414 }
415 case OP_LOADK: { 415 case OP_LOADK: {
416 setobj2s(ra, KBx(i)); 416 setobj2s(L, ra, KBx(i));
417 break; 417 break;
418 } 418 }
419 case OP_LOADBOOL: { 419 case OP_LOADBOOL: {
@@ -422,7 +422,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
422 break; 422 break;
423 } 423 }
424 case OP_LOADNIL: { 424 case OP_LOADNIL: {
425 TObject *rb = RB(i); 425 TValue *rb = RB(i);
426 do { 426 do {
427 setnilvalue(rb--); 427 setnilvalue(rb--);
428 } while (rb >= ra); 428 } while (rb >= ra);
@@ -430,11 +430,11 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
430 } 430 }
431 case OP_GETUPVAL: { 431 case OP_GETUPVAL: {
432 int b = GETARG_B(i); 432 int b = GETARG_B(i);
433 setobj2s(ra, cl->upvals[b]->v); 433 setobj2s(L, ra, cl->upvals[b]->v);
434 break; 434 break;
435 } 435 }
436 case OP_GETGLOBAL: { 436 case OP_GETGLOBAL: {
437 TObject *rb = KBx(i); 437 TValue *rb = KBx(i);
438 lua_assert(ttisstring(rb) && ttistable(&cl->g)); 438 lua_assert(ttisstring(rb) && ttistable(&cl->g));
439 L->ci->u.l.savedpc = pc; 439 L->ci->u.l.savedpc = pc;
440 luaV_gettable(L, &cl->g, rb, ra); /***/ 440 luaV_gettable(L, &cl->g, rb, ra); /***/
@@ -456,7 +456,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
456 } 456 }
457 case OP_SETUPVAL: { 457 case OP_SETUPVAL: {
458 UpVal *uv = cl->upvals[GETARG_B(i)]; 458 UpVal *uv = cl->upvals[GETARG_B(i)];
459 setobj(uv->v, ra); 459 setobj(L, uv->v, ra);
460 luaC_barrier(L, uv, ra); 460 luaC_barrier(L, uv, ra);
461 break; 461 break;
462 } 462 }
@@ -469,7 +469,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
469 case OP_NEWTABLE: { 469 case OP_NEWTABLE: {
470 int b = GETARG_B(i); 470 int b = GETARG_B(i);
471 b = fb2int(b); 471 b = fb2int(b);
472 sethvalue(ra, luaH_new(L, b, GETARG_C(i))); 472 sethvalue(L, ra, luaH_new(L, b, GETARG_C(i)));
473 L->ci->u.l.savedpc = pc; 473 L->ci->u.l.savedpc = pc;
474 luaC_checkGC(L); /***/ 474 luaC_checkGC(L); /***/
475 base = L->base; 475 base = L->base;
@@ -477,15 +477,15 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
477 } 477 }
478 case OP_SELF: { 478 case OP_SELF: {
479 StkId rb = RB(i); 479 StkId rb = RB(i);
480 setobjs2s(ra+1, rb); 480 setobjs2s(L, ra+1, rb);
481 L->ci->u.l.savedpc = pc; 481 L->ci->u.l.savedpc = pc;
482 luaV_gettable(L, rb, RKC(i), ra); /***/ 482 luaV_gettable(L, rb, RKC(i), ra); /***/
483 base = L->base; 483 base = L->base;
484 break; 484 break;
485 } 485 }
486 case OP_ADD: { 486 case OP_ADD: {
487 TObject *rb = RKB(i); 487 TValue *rb = RKB(i);
488 TObject *rc = RKC(i); 488 TValue *rc = RKC(i);
489 if (ttisnumber(rb) && ttisnumber(rc)) { 489 if (ttisnumber(rb) && ttisnumber(rc)) {
490 setnvalue(ra, nvalue(rb) + nvalue(rc)); 490 setnvalue(ra, nvalue(rb) + nvalue(rc));
491 } 491 }
@@ -494,8 +494,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
494 break; 494 break;
495 } 495 }
496 case OP_SUB: { 496 case OP_SUB: {
497 TObject *rb = RKB(i); 497 TValue *rb = RKB(i);
498 TObject *rc = RKC(i); 498 TValue *rc = RKC(i);
499 if (ttisnumber(rb) && ttisnumber(rc)) { 499 if (ttisnumber(rb) && ttisnumber(rc)) {
500 setnvalue(ra, nvalue(rb) - nvalue(rc)); 500 setnvalue(ra, nvalue(rb) - nvalue(rc));
501 } 501 }
@@ -504,8 +504,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
504 break; 504 break;
505 } 505 }
506 case OP_MUL: { 506 case OP_MUL: {
507 TObject *rb = RKB(i); 507 TValue *rb = RKB(i);
508 TObject *rc = RKC(i); 508 TValue *rc = RKC(i);
509 if (ttisnumber(rb) && ttisnumber(rc)) { 509 if (ttisnumber(rb) && ttisnumber(rc)) {
510 setnvalue(ra, nvalue(rb) * nvalue(rc)); 510 setnvalue(ra, nvalue(rb) * nvalue(rc));
511 } 511 }
@@ -514,8 +514,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
514 break; 514 break;
515 } 515 }
516 case OP_DIV: { 516 case OP_DIV: {
517 TObject *rb = RKB(i); 517 TValue *rb = RKB(i);
518 TObject *rc = RKC(i); 518 TValue *rc = RKC(i);
519 if (ttisnumber(rb) && ttisnumber(rc)) { 519 if (ttisnumber(rb) && ttisnumber(rc)) {
520 setnvalue(ra, nvalue(rb) / nvalue(rc)); 520 setnvalue(ra, nvalue(rb) / nvalue(rc));
521 } 521 }
@@ -528,8 +528,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
528 break; 528 break;
529 } 529 }
530 case OP_UNM: { 530 case OP_UNM: {
531 const TObject *rb = RB(i); 531 const TValue *rb = RB(i);
532 TObject temp; 532 TValue temp;
533 if (tonumber(rb, &temp)) { 533 if (tonumber(rb, &temp)) {
534 setnvalue(ra, -nvalue(rb)); 534 setnvalue(ra, -nvalue(rb));
535 } 535 }
@@ -554,7 +554,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
554 luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ 554 luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/
555 luaC_checkGC(L); /***/ 555 luaC_checkGC(L); /***/
556 base = L->base; 556 base = L->base;
557 setobjs2s(RA(i), base+b); 557 setobjs2s(L, RA(i), base+b);
558 break; 558 break;
559 } 559 }
560 case OP_JMP: { 560 case OP_JMP: {
@@ -583,10 +583,10 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
583 break; 583 break;
584 } 584 }
585 case OP_TEST: { 585 case OP_TEST: {
586 TObject *rb = RB(i); 586 TValue *rb = RB(i);
587 if (l_isfalse(rb) == GETARG_C(i)) pc++; 587 if (l_isfalse(rb) == GETARG_C(i)) pc++;
588 else { 588 else {
589 setobjs2s(ra, rb); 589 setobjs2s(L, ra, rb);
590 dojump(pc, GETARG_sBx(*pc) + 1); 590 dojump(pc, GETARG_sBx(*pc) + 1);
591 } 591 }
592 break; 592 break;
@@ -617,7 +617,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
617 ra = RA(i); 617 ra = RA(i);
618 if (L->openupval) luaF_close(L, base); 618 if (L->openupval) luaF_close(L, base);
619 for (aux = 0; ra+aux < L->top; aux++) /* move frame down */ 619 for (aux = 0; ra+aux < L->top; aux++) /* move frame down */
620 setobjs2s(base+aux-1, ra+aux); 620 setobjs2s(L, base+aux-1, ra+aux);
621 (L->ci - 1)->top = L->top = base+aux; /* correct top */ 621 (L->ci - 1)->top = L->top = base+aux; /* correct top */
622 (L->ci - 1)->u.l.savedpc = L->ci->u.l.savedpc; 622 (L->ci - 1)->u.l.savedpc = L->ci->u.l.savedpc;
623 (L->ci - 1)->u.l.tailcalls++; /* one more call lost */ 623 (L->ci - 1)->u.l.tailcalls++; /* one more call lost */
@@ -659,9 +659,9 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
659 break; 659 break;
660 } 660 }
661 case OP_FORPREP: { /***/ 661 case OP_FORPREP: { /***/
662 const TObject *init = ra; 662 const TValue *init = ra;
663 const TObject *plimit = ra+1; 663 const TValue *plimit = ra+1;
664 const TObject *pstep = ra+2; 664 const TValue *pstep = ra+2;
665 L->ci->u.l.savedpc = pc; 665 L->ci->u.l.savedpc = pc;
666 if (!tonumber(init, ra)) 666 if (!tonumber(init, ra))
667 luaG_runerror(L, "`for' initial value must be a number"); 667 luaG_runerror(L, "`for' initial value must be a number");
@@ -675,9 +675,9 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
675 } 675 }
676 case OP_TFORLOOP: { 676 case OP_TFORLOOP: {
677 StkId cb = ra + 3; /* call base */ 677 StkId cb = ra + 3; /* call base */
678 setobjs2s(cb+2, ra+2); 678 setobjs2s(L, cb+2, ra+2);
679 setobjs2s(cb+1, ra+1); 679 setobjs2s(L, cb+1, ra+1);
680 setobjs2s(cb, ra); 680 setobjs2s(L, cb, ra);
681 L->top = cb+3; /* func. + 2 args (state and index) */ 681 L->top = cb+3; /* func. + 2 args (state and index) */
682 L->ci->u.l.savedpc = pc; 682 L->ci->u.l.savedpc = pc;
683 luaD_call(L, cb, GETARG_C(i)); /***/ 683 luaD_call(L, cb, GETARG_C(i)); /***/
@@ -687,15 +687,15 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
687 if (ttisnil(cb)) /* break loop? */ 687 if (ttisnil(cb)) /* break loop? */
688 pc++; /* skip jump (break loop) */ 688 pc++; /* skip jump (break loop) */
689 else { 689 else {
690 setobjs2s(cb-1, cb); /* save control variable */ 690 setobjs2s(L, cb-1, cb); /* save control variable */
691 dojump(pc, GETARG_sBx(*pc) + 1); /* jump back */ 691 dojump(pc, GETARG_sBx(*pc) + 1); /* jump back */
692 } 692 }
693 break; 693 break;
694 } 694 }
695 case OP_TFORPREP: { /* for compatibility only */ 695 case OP_TFORPREP: { /* for compatibility only */
696 if (ttistable(ra)) { 696 if (ttistable(ra)) {
697 setobjs2s(ra+1, ra); 697 setobjs2s(L, ra+1, ra);
698 setobj2s(ra, luaH_getstr(hvalue(gt(L)), luaS_new(L, "next"))); 698 setobj2s(L, ra, luaH_getstr(hvalue(gt(L)), luaS_new(L, "next")));
699 } 699 }
700 dojump(pc, GETARG_sBx(i)); 700 dojump(pc, GETARG_sBx(i));
701 break; 701 break;
@@ -716,8 +716,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
716 } 716 }
717 bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ 717 bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
718 for (; n > 0; n--) { 718 for (; n > 0; n--) {
719 TObject *val = ra+n; 719 TValue *val = ra+n;
720 setobj2t(luaH_setnum(L, h, bc+n), val); 720 setobj2t(L, luaH_setnum(L, h, bc+n), val);
721 luaC_barrier(L, h, val); 721 luaC_barrier(L, h, val);
722 } 722 }
723 break; 723 break;
@@ -742,7 +742,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
742 ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc)); 742 ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));
743 } 743 }
744 } 744 }
745 setclvalue(ra, ncl); 745 setclvalue(L, ra, ncl);
746 L->ci->u.l.savedpc = pc; 746 L->ci->u.l.savedpc = pc;
747 luaC_checkGC(L); /***/ 747 luaC_checkGC(L); /***/
748 base = L->base; 748 base = L->base;
diff --git a/lvm.h b/lvm.h
index b2d9f8d5..defe611f 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 1.48 2003/05/05 18:39:57 roberto Exp $ 2** $Id: lvm.h,v 1.49 2003/07/16 20:49:02 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*/
@@ -22,12 +22,12 @@
22 (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 22 (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
23 23
24 24
25int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r); 25int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
26int luaV_equalval (lua_State *L, const TObject *t1, const TObject *t2); 26int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
27const TObject *luaV_tonumber (const TObject *obj, TObject *n); 27const TValue *luaV_tonumber (const TValue *obj, TValue *n);
28int luaV_tostring (lua_State *L, StkId obj); 28int luaV_tostring (lua_State *L, StkId obj);
29void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId val); 29void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val);
30void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val); 30void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val);
31StkId luaV_execute (lua_State *L, int nexeccalls); 31StkId luaV_execute (lua_State *L, int nexeccalls);
32void luaV_concat (lua_State *L, int total, int last); 32void luaV_concat (lua_State *L, int total, int last);
33 33
diff --git a/makefile b/makefile
index f9ffe3d9..6a9c0d91 100644
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
1# 1#
2## $Id: makefile,v 1.40 2003/03/19 21:27:30 roberto Exp roberto $ 2## $Id: makefile,v 1.41 2003/04/07 20:11:53 roberto Exp roberto $
3## Makefile 3## Makefile
4## See Copyright Notice in lua.h 4## See Copyright Notice in lua.h
5# 5#
@@ -8,7 +8,7 @@
8#CONFIGURATION 8#CONFIGURATION
9 9
10# -DEXTERNMEMCHECK -DHARDSTACKTESTS 10# -DEXTERNMEMCHECK -DHARDSTACKTESTS
11# DEBUG = -g -DLUA_USER_H='"ltests.h"' 11DEBUG = -g -DLUA_USER_H='"ltests.h"'
12OPTIMIZE = -O2 \ 12OPTIMIZE = -O2 \
13 -D'lua_number2int(i,d)=__asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d))' \ 13 -D'lua_number2int(i,d)=__asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d))' \
14# -fomit-frame-pointer 14# -fomit-frame-pointer
@@ -104,53 +104,53 @@ clear :
104 104
105 105
106lapi.o: lapi.c lua.h lapi.h lobject.h llimits.h ldebug.h lstate.h ltm.h \ 106lapi.o: lapi.c lua.h lapi.h lobject.h llimits.h ldebug.h lstate.h ltm.h \
107 lzio.h ldo.h lfunc.h lgc.h lmem.h lstring.h ltable.h lundump.h lvm.h 107 lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h lundump.h lvm.h
108lauxlib.o: lauxlib.c lua.h lauxlib.h 108lauxlib.o: lauxlib.c lua.h lauxlib.h
109lbaselib.o: lbaselib.c lua.h lauxlib.h lualib.h 109lbaselib.o: lbaselib.c lua.h lauxlib.h lualib.h
110lcode.o: lcode.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h \ 110lcode.o: lcode.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h lmem.h \
111 lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h lmem.h 111 lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h lgc.h
112ldblib.o: ldblib.c lua.h lauxlib.h lualib.h 112ldblib.o: ldblib.c lua.h lauxlib.h lualib.h
113ldebug.o: ldebug.c lua.h lapi.h lobject.h llimits.h lcode.h llex.h lzio.h \ 113ldebug.o: ldebug.c lua.h lapi.h lobject.h llimits.h lcode.h llex.h lzio.h \
114 lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h lfunc.h \ 114 lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h \
115 lstring.h lvm.h 115 lfunc.h lstring.h lgc.h lvm.h
116ldo.o: ldo.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \ 116ldo.o: ldo.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
117 ldo.h lfunc.h lgc.h lmem.h lopcodes.h lparser.h ltable.h lstring.h \ 117 lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h lstring.h \
118 lundump.h lvm.h 118 lundump.h lvm.h
119ldump.o: ldump.c lua.h lobject.h llimits.h lopcodes.h lstate.h ltm.h \ 119ldump.o: ldump.c lua.h lobject.h llimits.h lopcodes.h lstate.h ltm.h \
120 lzio.h lundump.h 120 lzio.h lmem.h lundump.h
121lfunc.o: lfunc.c lua.h lfunc.h lobject.h llimits.h lgc.h lmem.h lstate.h \ 121lfunc.o: lfunc.c lua.h lfunc.h lobject.h llimits.h lgc.h lmem.h lstate.h \
122 ltm.h lzio.h 122 ltm.h lzio.h
123lgc.o: lgc.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \ 123lgc.o: lgc.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
124 ldo.h lfunc.h lgc.h lmem.h lstring.h ltable.h 124 lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
125liolib.o: liolib.c lua.h lauxlib.h lualib.h 125liolib.o: liolib.c lua.h lauxlib.h lualib.h
126llex.o: llex.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h lzio.h \ 126llex.o: llex.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h lzio.h \
127 llex.h lparser.h ltable.h lstring.h 127 lmem.h llex.h lparser.h ltable.h lstring.h lgc.h
128lmathlib.o: lmathlib.c lua.h lauxlib.h lualib.h 128lmathlib.o: lmathlib.c lua.h lauxlib.h lualib.h
129lmem.o: lmem.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \ 129lmem.o: lmem.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
130 ldo.h lmem.h 130 lmem.h ldo.h
131lobject.o: lobject.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h \
132 lzio.h lmem.h lstring.h lvm.h
133loadlib.o: loadlib.c lua.h lauxlib.h lualib.h 131loadlib.o: loadlib.c lua.h lauxlib.h lualib.h
132lobject.o: lobject.c lua.h ldo.h lobject.h llimits.h lstate.h ltm.h \
133 lzio.h lmem.h lstring.h lgc.h lvm.h
134lopcodes.o: lopcodes.c lua.h lobject.h llimits.h lopcodes.h 134lopcodes.o: lopcodes.c lua.h lobject.h llimits.h lopcodes.h
135lparser.o: lparser.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h \ 135lparser.o: lparser.c lua.h lcode.h llex.h lobject.h llimits.h lzio.h \
136 lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h lfunc.h lmem.h \ 136 lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h ldo.h \
137 lstring.h 137 lfunc.h lstring.h lgc.h
138lstate.o: lstate.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ 138lstate.o: lstate.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
139 lzio.h ldo.h lfunc.h lgc.h llex.h lmem.h lstring.h ltable.h 139 lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h
140lstring.o: lstring.c lua.h lmem.h llimits.h lobject.h lstate.h ltm.h \ 140lstring.o: lstring.c lua.h lmem.h llimits.h lobject.h lstate.h ltm.h \
141 lzio.h lstring.h 141 lzio.h lstring.h lgc.h
142lstrlib.o: lstrlib.c lua.h lauxlib.h lualib.h 142lstrlib.o: lstrlib.c lua.h lauxlib.h lualib.h
143ltable.o: ltable.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ 143ltable.o: ltable.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
144 lzio.h ldo.h lgc.h lmem.h ltable.h 144 lzio.h lmem.h ldo.h lgc.h ltable.h
145ltablib.o: ltablib.c lua.h lauxlib.h lualib.h 145ltablib.o: ltablib.c lua.h lauxlib.h lualib.h
146ltests.o: ltests.c lua.h lapi.h lobject.h llimits.h lauxlib.h lcode.h \ 146ltests.o: ltests.c lua.h lapi.h lobject.h llimits.h lauxlib.h lcode.h \
147 llex.h lzio.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ 147 llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \
148 ldo.h lfunc.h lmem.h lstring.h lualib.h 148 ltm.h ldo.h lfunc.h lstring.h lgc.h lualib.h
149ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h lzio.h lstring.h \ 149ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h lzio.h lmem.h \
150 ltable.h 150 lstring.h lgc.h ltable.h
151lua.o: lua.c lua.h lauxlib.h lualib.h 151lua.o: lua.c lua.h lauxlib.h lualib.h
152lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ 152lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
153 lzio.h lfunc.h lmem.h lopcodes.h lstring.h lundump.h 153 lzio.h lmem.h ldo.h lfunc.h lopcodes.h lstring.h lgc.h lundump.h
154lvm.o: lvm.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \ 154lvm.o: lvm.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h lzio.h \
155 ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h 155 lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
156lzio.o: lzio.c lua.h llimits.h lmem.h lzio.h 156lzio.o: lzio.c lua.h llimits.h lmem.h lstate.h lobject.h ltm.h lzio.h