aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c6
-rw-r--r--lcode.c6
-rw-r--r--ldo.c9
-rw-r--r--ltable.c43
-rw-r--r--ltable.h8
-rw-r--r--ltm.c4
-rw-r--r--ltm.h3
-rw-r--r--lvm.c31
8 files changed, 57 insertions, 53 deletions
diff --git a/lapi.c b/lapi.c
index 5421cdf4..9ad290f7 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.191 2002/05/15 18:57:44 roberto Exp roberto $ 2** $Id: lapi.c,v 1.192 2002/05/16 18:39:46 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*/
@@ -500,7 +500,7 @@ LUA_API void lua_rawset (lua_State *L, int index) {
500 api_checknelems(L, 2); 500 api_checknelems(L, 2);
501 t = luaA_index(L, index); 501 t = luaA_index(L, index);
502 api_check(L, ttype(t) == LUA_TTABLE); 502 api_check(L, ttype(t) == LUA_TTABLE);
503 luaH_set(L, hvalue(t), L->top-2, L->top-1); 503 setobj(luaH_set(L, hvalue(t), L->top-2), L->top-1);
504 L->top -= 2; 504 L->top -= 2;
505 lua_unlock(L); 505 lua_unlock(L);
506} 506}
@@ -512,7 +512,7 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) {
512 api_checknelems(L, 1); 512 api_checknelems(L, 1);
513 o = luaA_index(L, index); 513 o = luaA_index(L, index);
514 api_check(L, ttype(o) == LUA_TTABLE); 514 api_check(L, ttype(o) == LUA_TTABLE);
515 luaH_setnum(L, hvalue(o), n, L->top-1); 515 setobj(luaH_setnum(L, hvalue(o), n), L->top-1);
516 L->top--; 516 L->top--;
517 lua_unlock(L); 517 lua_unlock(L);
518} 518}
diff --git a/lcode.c b/lcode.c
index 8a0ef0d9..2bf050dc 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.103 2002/05/13 13:07:48 roberto Exp roberto $ 2** $Id: lcode.c,v 1.104 2002/05/14 17:52:22 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*/
@@ -211,13 +211,11 @@ static int addk (FuncState *fs, TObject *k, TObject *v) {
211 return cast(int, nvalue(index)); 211 return cast(int, nvalue(index));
212 } 212 }
213 else { /* constant not found; create a new entry */ 213 else { /* constant not found; create a new entry */
214 TObject o;
215 Proto *f = fs->f; 214 Proto *f = fs->f;
216 luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject, 215 luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject,
217 MAXARG_Bx, "constant table overflow"); 216 MAXARG_Bx, "constant table overflow");
218 setobj(&f->k[fs->nk], v); 217 setobj(&f->k[fs->nk], v);
219 setnvalue(&o, fs->nk); 218 setnvalue(luaH_set(fs->L, fs->h, k), fs->nk);
220 luaH_set(fs->L, fs->h, k, &o);
221 return fs->nk++; 219 return fs->nk++;
222 } 220 }
223} 221}
diff --git a/ldo.c b/ldo.c
index 34914923..c11c5639 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.175 2002/05/15 18:57:44 roberto Exp roberto $ 2** $Id: ldo.c,v 1.176 2002/05/16 18:39:46 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*/
@@ -171,7 +171,7 @@ static void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event) {
171static void adjust_varargs (lua_State *L, int nfixargs) { 171static void adjust_varargs (lua_State *L, int nfixargs) {
172 int i; 172 int i;
173 Table *htab; 173 Table *htab;
174 TObject n, nname; 174 TObject nname;
175 int actual = L->top - L->ci->base; /* actual number of arguments */ 175 int actual = L->top - L->ci->base; /* actual number of arguments */
176 if (actual < nfixargs) { 176 if (actual < nfixargs) {
177 luaD_checkstack(L, nfixargs - actual); 177 luaD_checkstack(L, nfixargs - actual);
@@ -181,11 +181,10 @@ static void adjust_varargs (lua_State *L, int nfixargs) {
181 actual -= nfixargs; /* number of extra arguments */ 181 actual -= nfixargs; /* number of extra arguments */
182 htab = luaH_new(L, 0, 0); /* create `arg' table */ 182 htab = luaH_new(L, 0, 0); /* create `arg' table */
183 for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ 183 for (i=0; i<actual; i++) /* put extra arguments into `arg' table */
184 luaH_setnum(L, htab, i+1, L->top - actual + i); 184 setobj(luaH_setnum(L, htab, i+1), L->top - actual + i);
185 /* store counter in field `n' */ 185 /* store counter in field `n' */
186 setnvalue(&n, actual);
187 setsvalue(&nname, luaS_newliteral(L, "n")); 186 setsvalue(&nname, luaS_newliteral(L, "n"));
188 luaH_set(L, htab, &nname, &n); 187 setnvalue(luaH_set(L, htab, &nname), actual);
189 L->top -= actual; /* remove extra elements from the stack */ 188 L->top -= actual; /* remove extra elements from the stack */
190 sethvalue(L->top, htab); 189 sethvalue(L->top, htab);
191 incr_top(L); 190 incr_top(L);
diff --git a/ltable.c b/ltable.c
index fdd15b66..deb853d6 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.107 2002/05/13 13:38:59 roberto Exp roberto $ 2** $Id: ltable.c,v 1.108 2002/05/15 18:57:44 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*/
@@ -56,7 +56,7 @@
56#define hashboolean(t,p) (node(t, lmod(p, sizenode(t)))) 56#define hashboolean(t,p) (node(t, lmod(p, sizenode(t))))
57 57
58/* 58/*
59** for pointers, avoid modulus by power of 2, as they tend to have many 59** avoid modulus by power of 2 for pointers, as they tend to have many
60** 2 factors. 60** 2 factors.
61*/ 61*/
62#define hashpointer(t,p) (node(t, (IntPoint(p) % ((sizenode(t)-1)|1)))) 62#define hashpointer(t,p) (node(t, (IntPoint(p) % ((sizenode(t)-1)|1))))
@@ -261,7 +261,7 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
261 /* re-insert elements from vanishing slice */ 261 /* re-insert elements from vanishing slice */
262 for (i=nasize; i<oldasize; i++) { 262 for (i=nasize; i<oldasize; i++) {
263 if (ttype(&t->array[i]) != LUA_TNIL) 263 if (ttype(&t->array[i]) != LUA_TNIL)
264 luaH_setnum(L, t, i+1, &t->array[i]); 264 setobj(luaH_setnum(L, t, i+1), &t->array[i]);
265 } 265 }
266 /* shrink array */ 266 /* shrink array */
267 luaM_reallocvector(L, t->array, oldasize, nasize, TObject); 267 luaM_reallocvector(L, t->array, oldasize, nasize, TObject);
@@ -270,7 +270,7 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
270 for (i = twoto(oldhsize) - 1; i >= 0; i--) { 270 for (i = twoto(oldhsize) - 1; i >= 0; i--) {
271 Node *old = nold+i; 271 Node *old = nold+i;
272 if (ttype(val(old)) != LUA_TNIL) 272 if (ttype(val(old)) != LUA_TNIL)
273 luaH_set(L, t, key(old), val(old)); 273 setobj(luaH_set(L, t, key(old)), val(old));
274 } 274 }
275 if (oldhsize) 275 if (oldhsize)
276 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */ 276 luaM_freearray(L, nold, twoto(oldhsize), Node); /* free old array */
@@ -344,8 +344,8 @@ void luaH_remove (Table *t, Node *e) {
344** put new key in its main position; otherwise (colliding node is in its main 344** put new key in its main position; otherwise (colliding node is in its main
345** position), new key goes to an empty position. 345** position), new key goes to an empty position.
346*/ 346*/
347static void newkey (lua_State *L, Table *t, const TObject *key, 347static TObject *newkey (lua_State *L, Table *t, const TObject *key) {
348 const TObject *val) { 348 TObject *val;
349 Node *mp = luaH_mainposition(t, key); 349 Node *mp = luaH_mainposition(t, key);
350 if (ttype(val(mp)) != LUA_TNIL) { /* main position is not free? */ 350 if (ttype(val(mp)) != LUA_TNIL) { /* main position is not free? */
351 Node *othern = luaH_mainposition(t, key(mp)); /* `mp' of colliding node */ 351 Node *othern = luaH_mainposition(t, key(mp)); /* `mp' of colliding node */
@@ -367,14 +367,19 @@ static void newkey (lua_State *L, Table *t, const TObject *key,
367 } 367 }
368 setobj(key(mp), key); 368 setobj(key(mp), key);
369 lua_assert(ttype(val(mp)) == LUA_TNIL); 369 lua_assert(ttype(val(mp)) == LUA_TNIL);
370 settableval(val(mp), val);
371 for (;;) { /* correct `firstfree' */ 370 for (;;) { /* correct `firstfree' */
372 if (ttype(key(t->firstfree)) == LUA_TNIL) 371 if (ttype(key(t->firstfree)) == LUA_TNIL)
373 return; /* OK; table still has a free place */ 372 return val(mp); /* OK; table still has a free place */
374 else if (t->firstfree == t->node) break; /* cannot decrement from here */ 373 else if (t->firstfree == t->node) break; /* cannot decrement from here */
375 else (t->firstfree)--; 374 else (t->firstfree)--;
376 } 375 }
377 rehash(L, t); /* no more free places; must create one */ 376 /* no more free places; must create one */
377 setbvalue(val(mp), 0); /* avoid new key being removed */
378 rehash(L, t); /* grow table */
379 val = cast(TObject *, luaH_get(t, key)); /* get new position */
380 lua_assert(ttype(val) == LUA_TBOOLEAN);
381 setnilvalue(val);
382 return val;
378} 383}
379 384
380 385
@@ -444,28 +449,26 @@ const TObject *luaH_get (Table *t, const TObject *key) {
444} 449}
445 450
446 451
447void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val) { 452TObject *luaH_set (lua_State *L, Table *t, const TObject *key) {
448 const TObject *p = luaH_get(t, key); 453 const TObject *p = luaH_get(t, key);
449 if (p != &luaO_nilobject) { 454 t->flags = 0;
450 settableval(p, val); 455 if (p != &luaO_nilobject)
451 } 456 return cast(TObject *, p);
452 else { 457 else {
453 if (ttype(key) == LUA_TNIL) luaG_runerror(L, "table index is nil"); 458 if (ttype(key) == LUA_TNIL) luaG_runerror(L, "table index is nil");
454 newkey(L, t, key, val); 459 return newkey(L, t, key);
455 } 460 }
456 t->flags = 0;
457} 461}
458 462
459 463
460void luaH_setnum (lua_State *L, Table *t, int key, const TObject *val) { 464TObject *luaH_setnum (lua_State *L, Table *t, int key) {
461 const TObject *p = luaH_getnum(t, key); 465 const TObject *p = luaH_getnum(t, key);
462 if (p != &luaO_nilobject) { 466 if (p != &luaO_nilobject)
463 settableval(p, val); 467 return cast(TObject *, p);
464 }
465 else { 468 else {
466 TObject k; 469 TObject k;
467 setnvalue(&k, key); 470 setnvalue(&k, key);
468 newkey(L, t, &k, val); 471 return newkey(L, t, &k);
469 } 472 }
470} 473}
471 474
diff --git a/ltable.h b/ltable.h
index c42f1059..54fba106 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.h,v 1.40 2002/02/14 21:41:08 roberto Exp roberto $ 2** $Id: ltable.h,v 1.41 2002/03/11 12:45:00 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*/
@@ -14,14 +14,12 @@
14#define key(n) (&(n)->i_key) 14#define key(n) (&(n)->i_key)
15#define val(n) (&(n)->i_val) 15#define val(n) (&(n)->i_val)
16 16
17#define settableval(p,v) setobj(cast(TObject *, p), v)
18
19 17
20const TObject *luaH_getnum (Table *t, int key); 18const TObject *luaH_getnum (Table *t, int key);
21void luaH_setnum (lua_State *L, Table *t, int key, const TObject *val); 19TObject *luaH_setnum (lua_State *L, Table *t, int key);
22const TObject *luaH_getstr (Table *t, TString *key); 20const TObject *luaH_getstr (Table *t, TString *key);
23const TObject *luaH_get (Table *t, const TObject *key); 21const TObject *luaH_get (Table *t, const TObject *key);
24void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val); 22TObject *luaH_set (lua_State *L, Table *t, const TObject *key);
25Table *luaH_new (lua_State *L, int narray, int lnhash); 23Table *luaH_new (lua_State *L, int narray, int lnhash);
26void luaH_free (lua_State *L, Table *t); 24void luaH_free (lua_State *L, Table *t);
27int luaH_next (lua_State *L, Table *t, TObject *key); 25int luaH_next (lua_State *L, Table *t, TObject *key);
diff --git a/ltm.c b/ltm.c
index aaba8943..7b7b64a2 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.90 2002/04/30 13:01:48 roberto Exp roberto $ 2** $Id: ltm.c,v 1.91 2002/05/20 19:51:06 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*/
@@ -26,7 +26,7 @@ const char *const luaT_typenames[] = {
26 26
27void luaT_init (lua_State *L) { 27void luaT_init (lua_State *L) {
28 static const char *const luaT_eventname[] = { /* ORDER TM */ 28 static const char *const luaT_eventname[] = { /* ORDER TM */
29 "__gettable", "__settable", "__index", 29 "__gettable", "__settable", "__index", "__newindex",
30 "__gc", "__weakmode", 30 "__gc", "__weakmode",
31 "__add", "__sub", "__mul", "__div", 31 "__add", "__sub", "__mul", "__div",
32 "__pow", "__unm", "__lt", "__concat", 32 "__pow", "__unm", "__lt", "__concat",
diff --git a/ltm.h b/ltm.h
index ab6c375a..e6718492 100644
--- a/ltm.h
+++ b/ltm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.h,v 1.31 2002/01/09 21:50:35 roberto Exp roberto $ 2** $Id: ltm.h,v 1.32 2002/05/20 19:51:06 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*/
@@ -18,6 +18,7 @@ typedef enum {
18 TM_GETTABLE = 0, 18 TM_GETTABLE = 0,
19 TM_SETTABLE, 19 TM_SETTABLE,
20 TM_INDEX, 20 TM_INDEX,
21 TM_NEWINDEX,
21 TM_GC, 22 TM_GC,
22 TM_WEAKMODE, 23 TM_WEAKMODE,
23 TM_ADD, 24 TM_ADD,
diff --git a/lvm.c b/lvm.c
index c5f3e88d..7815db6c 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.231 2002/05/13 13:09:00 roberto Exp roberto $ 2** $Id: lvm.c,v 1.232 2002/05/15 18:57:44 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*/
@@ -114,13 +114,13 @@ void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
114 int loop = 0; 114 int loop = 0;
115 init: 115 init:
116 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */ 116 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
117 Table *et = hvalue(t)->metatable; 117 Table *h = hvalue(t);
118 Table *et = h->metatable;
118 if ((tm = fasttm(L, et, TM_GETTABLE)) == NULL) { /* no gettable TM? */ 119 if ((tm = fasttm(L, et, TM_GETTABLE)) == NULL) { /* no gettable TM? */
119 const TObject *h = luaH_get(hvalue(t), key); /* do a primitive get */ 120 const TObject *v = luaH_get(h, key); /* do a primitive get */
120 /* result is no nil or there is no `index' tag method? */ 121 if (ttype(v) != LUA_TNIL || /* result is no nil ... */
121 if (ttype(h) != LUA_TNIL || /* no nil? */ 122 (tm = fasttm(L, et, TM_INDEX)) == NULL) { /* ... or no index TM? */
122 (tm = fasttm(L, et, TM_INDEX)) == NULL) { /* or no index TM? */ 123 setobj(res, v); /* default get */
123 setobj(res, h); /* default get */
124 return; 124 return;
125 } 125 }
126 } 126 }
@@ -149,13 +149,18 @@ void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
149 int loop = 0; 149 int loop = 0;
150 init: 150 init:
151 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */ 151 if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
152 Table *et = hvalue(t)->metatable; 152 Table *h = hvalue(t);
153 if ((tm = fasttm(L, et, TM_SETTABLE)) == NULL) { /* no TM? */ 153 Table *et = h->metatable;
154 luaH_set(L, hvalue(t), key, val); /* do a primitive set */ 154 if ((tm = fasttm(L, et, TM_SETTABLE)) == NULL) { /* no settable TM? */
155 return; 155 TObject *oldval = luaH_set(L, h, key); /* do a primitive set */
156 if (ttype(oldval) != LUA_TNIL || /* result is no nil ... */
157 (tm = fasttm(L, et, TM_NEWINDEX)) == NULL) { /* ... or no TM? */
158 setobj(oldval, val);
159 return;
160 }
156 } 161 }
157 /* else will try the tag method */ 162 /* else will try the tag method */
158 } else { /* not a table; try a `settable' tag method */ 163 } else { /* `t' is not a table; try a `settable' tag method */
159 if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) { 164 if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) {
160 luaG_typeerror(L, t, "index"); 165 luaG_typeerror(L, t, "index");
161 return; /* to avoid warnings */ 166 return; /* to avoid warnings */
@@ -577,7 +582,7 @@ StkId luaV_execute (lua_State *L) {
577 } 582 }
578 bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ 583 bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
579 for (; n > 0; n--) 584 for (; n > 0; n--)
580 luaH_setnum(L, h, bc+n, ra+n); 585 setobj(luaH_setnum(L, h, bc+n), ra+n);
581 break; 586 break;
582 } 587 }
583 case OP_CLOSE: { 588 case OP_CLOSE: {