diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-18 13:59:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-18 13:59:09 -0200 |
commit | f2c451d7455aad3496f32dfa2bfca7f7e8b5376d (patch) | |
tree | 38e30f839516ff5b6178351750b5e3256f4dd98e | |
parent | 619edfd9e4c210bdfcfbf1e911d1760c53c4293f (diff) | |
download | lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.tar.gz lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.tar.bz2 lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.zip |
all accesses to TObjects done through macros
-rw-r--r-- | lapi.c | 62 | ||||
-rw-r--r-- | ldebug.c | 11 | ||||
-rw-r--r-- | ldo.c | 25 | ||||
-rw-r--r-- | lgc.c | 20 | ||||
-rw-r--r-- | liolib.c | 8 | ||||
-rw-r--r-- | lobject.h | 59 | ||||
-rw-r--r-- | ltable.c | 18 | ||||
-rw-r--r-- | ltests.c | 5 | ||||
-rw-r--r-- | ltm.c | 7 | ||||
-rw-r--r-- | lvm.c | 143 |
10 files changed, 173 insertions, 185 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.115 2001/01/10 17:41:50 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.116 2001/01/10 18: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 | */ |
@@ -33,7 +33,6 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | |||
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | |||
37 | TObject *luaA_index (lua_State *L, int index) { | 36 | TObject *luaA_index (lua_State *L, int index) { |
38 | return Index(L, index); | 37 | return Index(L, index); |
39 | } | 38 | } |
@@ -50,7 +49,7 @@ static TObject *luaA_indexAcceptable (lua_State *L, int index) { | |||
50 | 49 | ||
51 | 50 | ||
52 | void luaA_pushobject (lua_State *L, const TObject *o) { | 51 | void luaA_pushobject (lua_State *L, const TObject *o) { |
53 | *L->top = *o; | 52 | setobj(L->top, o); |
54 | incr_top; | 53 | incr_top; |
55 | } | 54 | } |
56 | 55 | ||
@@ -80,7 +79,7 @@ LUA_API void lua_settop (lua_State *L, int index) { | |||
80 | 79 | ||
81 | LUA_API void lua_remove (lua_State *L, int index) { | 80 | LUA_API void lua_remove (lua_State *L, int index) { |
82 | StkId p = luaA_index(L, index); | 81 | StkId p = luaA_index(L, index); |
83 | while (++p < L->top) *(p-1) = *p; | 82 | while (++p < L->top) setobj(p-1, p); |
84 | L->top--; | 83 | L->top--; |
85 | } | 84 | } |
86 | 85 | ||
@@ -88,14 +87,13 @@ LUA_API void lua_remove (lua_State *L, int index) { | |||
88 | LUA_API void lua_insert (lua_State *L, int index) { | 87 | LUA_API void lua_insert (lua_State *L, int index) { |
89 | StkId p = luaA_index(L, index); | 88 | StkId p = luaA_index(L, index); |
90 | StkId q; | 89 | StkId q; |
91 | for (q = L->top; q>p; q--) | 90 | for (q = L->top; q>p; q--) setobj(q, q-1); |
92 | *q = *(q-1); | 91 | setobj(p, L->top); |
93 | *p = *L->top; | ||
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
97 | LUA_API void lua_pushvalue (lua_State *L, int index) { | 95 | LUA_API void lua_pushvalue (lua_State *L, int index) { |
98 | *L->top = *luaA_index(L, index); | 96 | setobj(L->top, luaA_index(L, index)); |
99 | api_incr_top(L); | 97 | api_incr_top(L); |
100 | } | 98 | } |
101 | 99 | ||
@@ -200,21 +198,19 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
200 | 198 | ||
201 | 199 | ||
202 | LUA_API void lua_pushnil (lua_State *L) { | 200 | LUA_API void lua_pushnil (lua_State *L) { |
203 | ttype(L->top) = LUA_TNIL; | 201 | setnilvalue(L->top); |
204 | api_incr_top(L); | 202 | api_incr_top(L); |
205 | } | 203 | } |
206 | 204 | ||
207 | 205 | ||
208 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 206 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
209 | nvalue(L->top) = n; | 207 | setnvalue(L->top, n); |
210 | ttype(L->top) = LUA_TNUMBER; | ||
211 | api_incr_top(L); | 208 | api_incr_top(L); |
212 | } | 209 | } |
213 | 210 | ||
214 | 211 | ||
215 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 212 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
216 | tsvalue(L->top) = luaS_newlstr(L, s, len); | 213 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
217 | ttype(L->top) = LUA_TSTRING; | ||
218 | api_incr_top(L); | 214 | api_incr_top(L); |
219 | } | 215 | } |
220 | 216 | ||
@@ -236,8 +232,7 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | |||
236 | /* ORDER LUA_T */ | 232 | /* ORDER LUA_T */ |
237 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) | 233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) |
238 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
239 | tsvalue(L->top) = luaS_createudata(L, u, tag); | 235 | setuvalue(L->top, luaS_createudata(L, u, tag)); |
240 | ttype(L->top) = LUA_TUSERDATA; | ||
241 | api_incr_top(L); | 236 | api_incr_top(L); |
242 | } | 237 | } |
243 | 238 | ||
@@ -250,7 +245,7 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | |||
250 | 245 | ||
251 | LUA_API void lua_getglobal (lua_State *L, const char *name) { | 246 | LUA_API void lua_getglobal (lua_State *L, const char *name) { |
252 | StkId top = L->top; | 247 | StkId top = L->top; |
253 | *top = *luaV_getglobal(L, luaS_new(L, name)); | 248 | setobj(top, luaV_getglobal(L, luaS_new(L, name))); |
254 | L->top = top; | 249 | L->top = top; |
255 | api_incr_top(L); | 250 | api_incr_top(L); |
256 | } | 251 | } |
@@ -259,7 +254,7 @@ LUA_API void lua_getglobal (lua_State *L, const char *name) { | |||
259 | LUA_API void lua_gettable (lua_State *L, int index) { | 254 | LUA_API void lua_gettable (lua_State *L, int index) { |
260 | StkId t = Index(L, index); | 255 | StkId t = Index(L, index); |
261 | StkId top = L->top; | 256 | StkId top = L->top; |
262 | *(top-1) = *luaV_gettable(L, t); | 257 | setobj(top-1, luaV_gettable(L, t)); |
263 | L->top = top; /* tag method may change top */ | 258 | L->top = top; /* tag method may change top */ |
264 | } | 259 | } |
265 | 260 | ||
@@ -267,31 +262,32 @@ LUA_API void lua_gettable (lua_State *L, int index) { | |||
267 | LUA_API void lua_rawget (lua_State *L, int index) { | 262 | LUA_API void lua_rawget (lua_State *L, int index) { |
268 | StkId t = Index(L, index); | 263 | StkId t = Index(L, index); |
269 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 264 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
270 | *(L->top - 1) = *luaH_get(hvalue(t), L->top - 1); | 265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
271 | } | 266 | } |
272 | 267 | ||
273 | 268 | ||
274 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
275 | StkId o = Index(L, index); | 270 | StkId o = Index(L, index); |
276 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 271 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); |
277 | *L->top = *luaH_getnum(hvalue(o), n); | 272 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
278 | api_incr_top(L); | 273 | api_incr_top(L); |
279 | } | 274 | } |
280 | 275 | ||
281 | 276 | ||
282 | LUA_API void lua_getglobals (lua_State *L) { | 277 | LUA_API void lua_getglobals (lua_State *L) { |
283 | hvalue(L->top) = L->gt; | 278 | sethvalue(L->top, L->gt); |
284 | ttype(L->top) = LUA_TTABLE; | ||
285 | api_incr_top(L); | 279 | api_incr_top(L); |
286 | } | 280 | } |
287 | 281 | ||
288 | 282 | ||
289 | LUA_API int lua_getref (lua_State *L, int ref) { | 283 | LUA_API int lua_getref (lua_State *L, int ref) { |
290 | if (ref == LUA_REFNIL) | 284 | if (ref == LUA_REFNIL) { |
291 | ttype(L->top) = LUA_TNIL; | 285 | setnilvalue(L->top); |
286 | } | ||
292 | else if (0 <= ref && ref < L->nref && | 287 | else if (0 <= ref && ref < L->nref && |
293 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) | 288 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) { |
294 | *L->top = L->refArray[ref].o; | 289 | setobj(L->top, &L->refArray[ref].o); |
290 | } | ||
295 | else | 291 | else |
296 | return 0; | 292 | return 0; |
297 | api_incr_top(L); | 293 | api_incr_top(L); |
@@ -300,8 +296,7 @@ LUA_API int lua_getref (lua_State *L, int ref) { | |||
300 | 296 | ||
301 | 297 | ||
302 | LUA_API void lua_newtable (lua_State *L) { | 298 | LUA_API void lua_newtable (lua_State *L) { |
303 | hvalue(L->top) = luaH_new(L, 0); | 299 | sethvalue(L->top, luaH_new(L, 0)); |
304 | ttype(L->top) = LUA_TTABLE; | ||
305 | api_incr_top(L); | 300 | api_incr_top(L); |
306 | } | 301 | } |
307 | 302 | ||
@@ -330,7 +325,7 @@ LUA_API void lua_settable (lua_State *L, int index) { | |||
330 | LUA_API void lua_rawset (lua_State *L, int index) { | 325 | LUA_API void lua_rawset (lua_State *L, int index) { |
331 | StkId t = Index(L, index); | 326 | StkId t = Index(L, index); |
332 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 327 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
333 | *luaH_set(L, hvalue(t), L->top-2) = *(L->top-1); | 328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
334 | L->top -= 2; | 329 | L->top -= 2; |
335 | } | 330 | } |
336 | 331 | ||
@@ -338,7 +333,7 @@ LUA_API void lua_rawset (lua_State *L, int index) { | |||
338 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
339 | StkId o = Index(L, index); | 334 | StkId o = Index(L, index); |
340 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 335 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); |
341 | *luaH_setnum(L, hvalue(o), n) = *(L->top-1); | 336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
342 | L->top--; | 337 | L->top--; |
343 | } | 338 | } |
344 | 339 | ||
@@ -364,7 +359,7 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
364 | MAX_INT, "reference table overflow"); | 359 | MAX_INT, "reference table overflow"); |
365 | ref = L->nref++; | 360 | ref = L->nref++; |
366 | } | 361 | } |
367 | L->refArray[ref].o = *(L->top-1); | 362 | setobj(&L->refArray[ref].o, L->top-1); |
368 | L->refArray[ref].st = lock ? LOCK : HOLD; | 363 | L->refArray[ref].st = lock ? LOCK : HOLD; |
369 | } | 364 | } |
370 | L->top--; | 365 | L->top--; |
@@ -442,8 +437,8 @@ LUA_API int lua_next (lua_State *L, int index) { | |||
442 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 437 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
443 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
444 | if (n) { | 439 | if (n) { |
445 | *(L->top-1) = *key(n); | 440 | setobj(L->top-1, key(n)); |
446 | *L->top = *val(n); | 441 | setobj(L->top, val(n)); |
447 | api_incr_top(L); | 442 | api_incr_top(L); |
448 | return 1; | 443 | return 1; |
449 | } | 444 | } |
@@ -485,8 +480,7 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
485 | 480 | ||
486 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | 481 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { |
487 | TString *ts = luaS_newudata(L, size, NULL); | 482 | TString *ts = luaS_newudata(L, size, NULL); |
488 | tsvalue(L->top) = ts; | 483 | setuvalue(L->top, ts); |
489 | ttype(L->top) = LUA_TUSERDATA; | ||
490 | api_incr_top(L); | 484 | api_incr_top(L); |
491 | return ts->u.d.value; | 485 | return ts->u.d.value; |
492 | } | 486 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.51 2000/11/30 18:50:47 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.52 2000/12/26 18:46:09 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 | */ |
@@ -29,10 +29,9 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name); | |||
29 | 29 | ||
30 | static void setnormalized (TObject *d, const TObject *s) { | 30 | static void setnormalized (TObject *d, const TObject *s) { |
31 | if (ttype(s) == LUA_TMARK) { | 31 | if (ttype(s) == LUA_TMARK) { |
32 | clvalue(d) = infovalue(s)->func; | 32 | setclvalue(d, infovalue(s)->func); |
33 | ttype(d) = LUA_TFUNCTION; | ||
34 | } | 33 | } |
35 | else *d = *s; | 34 | else setobj(d, s); |
36 | } | 35 | } |
37 | 36 | ||
38 | 37 | ||
@@ -58,7 +57,7 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { | |||
58 | static StkId aux_stackedfunction (lua_State *L, int level, StkId top) { | 57 | static StkId aux_stackedfunction (lua_State *L, int level, StkId top) { |
59 | int i; | 58 | int i; |
60 | for (i = (top-1) - L->stack; i>=0; i--) { | 59 | for (i = (top-1) - L->stack; i>=0; i--) { |
61 | if (is_T_MARK(L->stack[i].ttype)) { | 60 | if (is_T_MARK(&L->stack[i])) { |
62 | if (level == 0) | 61 | if (level == 0) |
63 | return L->stack+i; | 62 | return L->stack+i; |
64 | level--; | 63 | level--; |
@@ -168,7 +167,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
168 | if (!fp) return NULL; /* `f' is not a Lua function? */ | 167 | if (!fp) return NULL; /* `f' is not a Lua function? */ |
169 | name = luaF_getlocalname(fp, n, currentpc(f)); | 168 | name = luaF_getlocalname(fp, n, currentpc(f)); |
170 | if (!name || name[0] == '(') return NULL; /* `(' starts private locals */ | 169 | if (!name || name[0] == '(') return NULL; /* `(' starts private locals */ |
171 | *((f+1)+(n-1)) = *L->top; | 170 | setobj((f+1)+(n-1), L->top); |
172 | return name; | 171 | return name; |
173 | } | 172 | } |
174 | 173 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.112 2001/01/10 16:58:11 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.113 2001/01/10 18:56:11 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 | */ |
@@ -74,7 +74,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) { | |||
74 | else { | 74 | else { |
75 | luaD_checkstack(L, diff); | 75 | luaD_checkstack(L, diff); |
76 | while (diff--) | 76 | while (diff--) |
77 | ttype(L->top++) = LUA_TNIL; | 77 | setnilvalue(L->top++); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
@@ -84,7 +84,7 @@ void luaD_adjusttop (lua_State *L, StkId base, int extra) { | |||
84 | */ | 84 | */ |
85 | static void luaD_openstack (lua_State *L, StkId pos) { | 85 | static void luaD_openstack (lua_State *L, StkId pos) { |
86 | int i = L->top-pos; | 86 | int i = L->top-pos; |
87 | while (i--) pos[i+1] = pos[i]; | 87 | while (i--) setobj(pos+i+1, pos+i); |
88 | incr_top; | 88 | incr_top; |
89 | } | 89 | } |
90 | 90 | ||
@@ -132,7 +132,7 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
132 | L->Cbase = base; /* new base for C function */ | 132 | L->Cbase = base; /* new base for C function */ |
133 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ | 133 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ |
134 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 134 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
135 | *(L->top++) = cl->upvalue[n]; | 135 | setobj(L->top++, &cl->upvalue[n]); |
136 | n = (*cl->f.c)(L); /* do the actual call */ | 136 | n = (*cl->f.c)(L); /* do the actual call */ |
137 | L->Cbase = old_Cbase; /* restore old C base */ | 137 | L->Cbase = old_Cbase; /* restore old C base */ |
138 | return L->top - n; /* return index of first result */ | 138 | return L->top - n; /* return index of first result */ |
@@ -142,8 +142,7 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
142 | void luaD_callTM (lua_State *L, Closure *f, int nParams, int nResults) { | 142 | void luaD_callTM (lua_State *L, Closure *f, int nParams, int nResults) { |
143 | StkId base = L->top - nParams; | 143 | StkId base = L->top - nParams; |
144 | luaD_openstack(L, base); | 144 | luaD_openstack(L, base); |
145 | clvalue(base) = f; | 145 | setclvalue(base, f); |
146 | ttype(base) = LUA_TFUNCTION; | ||
147 | luaD_call(L, base, nResults); | 146 | luaD_call(L, base, nResults); |
148 | } | 147 | } |
149 | 148 | ||
@@ -166,13 +165,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
166 | if (tm == NULL) | 165 | if (tm == NULL) |
167 | luaG_typeerror(L, func, "call"); | 166 | luaG_typeerror(L, func, "call"); |
168 | luaD_openstack(L, func); | 167 | luaD_openstack(L, func); |
169 | clvalue(func) = tm; /* tag method is the new function to be called */ | 168 | setclvalue(func, tm); /* tag method is the new function to be called */ |
170 | ttype(func) = LUA_TFUNCTION; | ||
171 | } | 169 | } |
172 | cl = clvalue(func); | 170 | cl = clvalue(func); |
173 | ci.func = cl; | 171 | ci.func = cl; |
174 | infovalue(func) = &ci; | 172 | setivalue(func, &ci); |
175 | ttype(func) = LUA_TMARK; | ||
176 | callhook = L->callhook; | 173 | callhook = L->callhook; |
177 | if (callhook) | 174 | if (callhook) |
178 | luaD_callHook(L, func, callhook, "call"); | 175 | luaD_callHook(L, func, callhook, "call"); |
@@ -184,15 +181,15 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
184 | /* move results to `func' (to erase parameters and function) */ | 181 | /* move results to `func' (to erase parameters and function) */ |
185 | if (nResults == LUA_MULTRET) { | 182 | if (nResults == LUA_MULTRET) { |
186 | while (firstResult < L->top) /* copy all results */ | 183 | while (firstResult < L->top) /* copy all results */ |
187 | *func++ = *firstResult++; | 184 | setobj(func++, firstResult++); |
188 | L->top = func; | 185 | L->top = func; |
189 | } | 186 | } |
190 | else { /* copy at most `nResults' */ | 187 | else { /* copy at most `nResults' */ |
191 | for (; nResults > 0 && firstResult < L->top; nResults--) | 188 | for (; nResults > 0 && firstResult < L->top; nResults--) |
192 | *func++ = *firstResult++; | 189 | setobj(func++, firstResult++); |
193 | L->top = func; | 190 | L->top = func; |
194 | for (; nResults > 0; nResults--) { /* if there are not enough results */ | 191 | for (; nResults > 0; nResults--) { /* if there are not enough results */ |
195 | ttype(L->top) = LUA_TNIL; /* adjust the stack */ | 192 | setnilvalue(L->top); /* adjust the stack */ |
196 | incr_top; /* must check stack space */ | 193 | incr_top; /* must check stack space */ |
197 | } | 194 | } |
198 | } | 195 | } |
@@ -334,7 +331,7 @@ struct lua_longjmp { | |||
334 | static void message (lua_State *L, const char *s) { | 331 | static void message (lua_State *L, const char *s) { |
335 | const TObject *em = luaH_getstr(L->gt, luaS_newliteral(L, LUA_ERRORMESSAGE)); | 332 | const TObject *em = luaH_getstr(L->gt, luaS_newliteral(L, LUA_ERRORMESSAGE)); |
336 | if (ttype(em) == LUA_TFUNCTION) { | 333 | if (ttype(em) == LUA_TFUNCTION) { |
337 | *L->top = *em; | 334 | setobj(L->top, em); |
338 | incr_top; | 335 | incr_top; |
339 | lua_pushstring(L, s); | 336 | lua_pushstring(L, s); |
340 | luaD_call(L, L->top-2, 0); | 337 | luaD_call(L, L->top-2, 0); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.74 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.75 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -145,7 +145,7 @@ static void markall (lua_State *L) { | |||
145 | 145 | ||
146 | static int hasmark (const TObject *o) { | 146 | static int hasmark (const TObject *o) { |
147 | /* valid only for locked objects */ | 147 | /* valid only for locked objects */ |
148 | switch (o->ttype) { | 148 | switch (ttype(o)) { |
149 | case LUA_TSTRING: case LUA_TUSERDATA: | 149 | case LUA_TSTRING: case LUA_TUSERDATA: |
150 | return tsvalue(o)->marked; | 150 | return tsvalue(o)->marked; |
151 | case LUA_TTABLE: | 151 | case LUA_TTABLE: |
@@ -290,15 +290,14 @@ static void checkMbuffer (lua_State *L) { | |||
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | static void callgcTM (lua_State *L, const TObject *o) { | 293 | static void callgcTM (lua_State *L, const TObject *obj) { |
294 | Closure *tm = luaT_gettmbyObj(L, o, TM_GC); | 294 | Closure *tm = luaT_gettmbyObj(L, obj, TM_GC); |
295 | if (tm != NULL) { | 295 | if (tm != NULL) { |
296 | int oldah = L->allowhooks; | 296 | int oldah = L->allowhooks; |
297 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ | 297 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ |
298 | luaD_checkstack(L, 2); | 298 | luaD_checkstack(L, 2); |
299 | clvalue(L->top) = tm; | 299 | setclvalue(L->top, tm); |
300 | ttype(L->top) = LUA_TFUNCTION; | 300 | setobj(L->top+1, obj); |
301 | *(L->top+1) = *o; | ||
302 | L->top += 2; | 301 | L->top += 2; |
303 | luaD_call(L, L->top-2, 0); | 302 | luaD_call(L, L->top-2, 0); |
304 | L->allowhooks = oldah; /* restore hooks */ | 303 | L->allowhooks = oldah; /* restore hooks */ |
@@ -308,15 +307,14 @@ static void callgcTM (lua_State *L, const TObject *o) { | |||
308 | 307 | ||
309 | static void callgcTMudata (lua_State *L) { | 308 | static void callgcTMudata (lua_State *L) { |
310 | int tag; | 309 | int tag; |
311 | TObject o; | ||
312 | ttype(&o) = LUA_TUSERDATA; | ||
313 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ | 310 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ |
314 | for (tag=L->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ | 311 | for (tag=L->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ |
315 | TString *udata; | 312 | TString *udata; |
316 | while ((udata = L->TMtable[tag].collected) != NULL) { | 313 | while ((udata = L->TMtable[tag].collected) != NULL) { |
314 | TObject obj; | ||
317 | L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ | 315 | L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ |
318 | tsvalue(&o) = udata; | 316 | setuvalue(&obj, udata); |
319 | callgcTM(L, &o); | 317 | callgcTM(L, &obj); |
320 | luaM_free(L, udata, sizeudata(udata->len)); | 318 | luaM_free(L, udata, sizeudata(udata->len)); |
321 | } | 319 | } |
322 | } | 320 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.97 2001/01/10 16:58:11 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.98 2001/01/11 18:59:03 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -87,11 +87,11 @@ static int pushresult (lua_State *L, int i) { | |||
87 | 87 | ||
88 | 88 | ||
89 | static FILE *gethandle (lua_State *L, IOCtrl *ctrl, int f) { | 89 | static FILE *gethandle (lua_State *L, IOCtrl *ctrl, int f) { |
90 | void *p = lua_touserdata(L, f); | 90 | FILE *p = (FILE *)lua_touserdata(L, f); |
91 | if (p != NULL) { /* is `f' a userdata ? */ | 91 | if (p != NULL) { /* is `f' a userdata ? */ |
92 | int ftag = lua_tag(L, f); | 92 | int ftag = lua_tag(L, f); |
93 | if (ftag == ctrl->iotag) /* does it have the correct tag? */ | 93 | if (ftag == ctrl->iotag) /* does it have the correct tag? */ |
94 | return (FILE *)p; | 94 | return p; |
95 | else if (ftag == ctrl->closedtag) | 95 | else if (ftag == ctrl->closedtag) |
96 | lua_error(L, "cannot access a closed file"); | 96 | lua_error(L, "cannot access a closed file"); |
97 | /* else go through */ | 97 | /* else go through */ |
@@ -496,7 +496,7 @@ static int getfield (lua_State *L, const char *key, int d) { | |||
496 | lua_pushstring(L, key); | 496 | lua_pushstring(L, key); |
497 | lua_rawget(L, -2); | 497 | lua_rawget(L, -2); |
498 | if (lua_isnumber(L, -1)) | 498 | if (lua_isnumber(L, -1)) |
499 | res = lua_tonumber(L, -1); | 499 | res = (int)lua_tonumber(L, -1); |
500 | else { | 500 | else { |
501 | if (d == -2) | 501 | if (d == -2) |
502 | luaL_verror(L, "field `%.20s' missing in date table", key); | 502 | luaL_verror(L, "field `%.20s' missing in date table", key); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.84 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.85 2000/12/28 12:55:41 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 | */ |
@@ -40,32 +40,61 @@ | |||
40 | 40 | ||
41 | 41 | ||
42 | /* check whether `t' is a mark */ | 42 | /* check whether `t' is a mark */ |
43 | #define is_T_MARK(t) ((t) == LUA_TMARK) | 43 | #define is_T_MARK(t) (ttype(t) == LUA_TMARK) |
44 | 44 | ||
45 | 45 | ||
46 | typedef union { | 46 | typedef union { |
47 | struct TString *ts; /* LUA_TSTRING, LUA_TUSERDATA */ | 47 | void *v; |
48 | struct Closure *cl; /* LUA_TFUNCTION */ | ||
49 | struct Hash *a; /* LUA_TTABLE */ | ||
50 | struct CallInfo *i; /* LUA_TLMARK */ | ||
51 | lua_Number n; /* LUA_TNUMBER */ | 48 | lua_Number n; /* LUA_TNUMBER */ |
52 | } Value; | 49 | } Value; |
53 | 50 | ||
54 | 51 | ||
52 | typedef struct lua_TObject { | ||
53 | int tt; | ||
54 | Value value; | ||
55 | } TObject; | ||
56 | |||
57 | |||
55 | /* Macros to access values */ | 58 | /* Macros to access values */ |
56 | #define ttype(o) ((o)->ttype) | 59 | #define ttype(o) ((o)->tt) |
57 | #define nvalue(o) ((o)->value.n) | 60 | #define nvalue(o) ((o)->value.n) |
58 | #define tsvalue(o) ((o)->value.ts) | 61 | #define tsvalue(o) ((struct TString *)(o)->value.v) |
59 | #define clvalue(o) ((o)->value.cl) | 62 | #define clvalue(o) ((struct Closure *)(o)->value.v) |
60 | #define hvalue(o) ((o)->value.a) | 63 | #define hvalue(o) ((struct Hash *)(o)->value.v) |
61 | #define infovalue(o) ((o)->value.i) | 64 | #define infovalue(o) ((struct CallInfo *)(o)->value.v) |
62 | #define svalue(o) (tsvalue(o)->str) | 65 | #define svalue(o) (tsvalue(o)->str) |
63 | 66 | ||
64 | 67 | ||
65 | typedef struct lua_TObject { | 68 | /* Macros to set values */ |
66 | int ttype; | 69 | #define setnvalue(obj,x) \ |
67 | Value value; | 70 | { TObject *o=(obj); o->tt=LUA_TNUMBER; o->value.n=(x); } |
68 | } TObject; | 71 | |
72 | #define setsvalue(obj,x) \ | ||
73 | { TObject *o=(obj); struct TString *v=(x); \ | ||
74 | o->tt=LUA_TSTRING; o->value.v=v; } | ||
75 | |||
76 | #define setuvalue(obj,x) \ | ||
77 | { TObject *o=(obj); struct TString *v=(x); \ | ||
78 | o->tt=LUA_TUSERDATA; o->value.v=v; } | ||
79 | |||
80 | #define setclvalue(obj,x) \ | ||
81 | { TObject *o=(obj); struct Closure *v=(x); \ | ||
82 | o->tt=LUA_TFUNCTION; o->value.v=v; } | ||
83 | |||
84 | #define sethvalue(obj,x) \ | ||
85 | { TObject *o=(obj); struct Hash *v=(x); \ | ||
86 | o->tt=LUA_TTABLE; o->value.v=v; } | ||
87 | |||
88 | #define setivalue(obj,x) \ | ||
89 | { TObject *o=(obj); struct CallInfo *v=(x); \ | ||
90 | o->tt=LUA_TMARK; o->value.v=v; } | ||
91 | |||
92 | #define setnilvalue(obj) { (obj)->tt=LUA_TNIL; } | ||
93 | |||
94 | #define setobj(obj1,obj2) \ | ||
95 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ | ||
96 | o1->tt=o2->tt; o1->value = o2->value; } | ||
97 | |||
69 | 98 | ||
70 | 99 | ||
71 | /* | 100 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.62 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.63 2001/01/10 18: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 | */ |
@@ -143,8 +143,7 @@ void luaH_remove (Hash *t, TObject *key) { | |||
143 | return; /* give up; (to avoid overflow) */ | 143 | return; /* give up; (to avoid overflow) */ |
144 | n += t->size; | 144 | n += t->size; |
145 | } | 145 | } |
146 | ttype(key) = LUA_TNUMBER; | 146 | setnvalue(key, n); |
147 | nvalue(key) = n; | ||
148 | LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash"); | 147 | LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash"); |
149 | } | 148 | } |
150 | } | 149 | } |
@@ -156,7 +155,8 @@ static void setnodevector (lua_State *L, Hash *t, luint32 size) { | |||
156 | lua_error(L, "table overflow"); | 155 | lua_error(L, "table overflow"); |
157 | t->node = luaM_newvector(L, size, Node); | 156 | t->node = luaM_newvector(L, size, Node); |
158 | for (i=0; i<(int)size; i++) { | 157 | for (i=0; i<(int)size; i++) { |
159 | ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; | 158 | setnilvalue(&t->node[i].key); |
159 | setnilvalue(&t->node[i].val); | ||
160 | t->node[i].next = NULL; | 160 | t->node[i].next = NULL; |
161 | } | 161 | } |
162 | t->size = size; | 162 | t->size = size; |
@@ -212,7 +212,7 @@ static void rehash (lua_State *L, Hash *t) { | |||
212 | for (i=0; i<oldsize; i++) { | 212 | for (i=0; i<oldsize; i++) { |
213 | Node *old = nold+i; | 213 | Node *old = nold+i; |
214 | if (ttype(&old->val) != LUA_TNIL) | 214 | if (ttype(&old->val) != LUA_TNIL) |
215 | *luaH_set(L, t, &old->key) = old->val; | 215 | setobj(luaH_set(L, t, &old->key), &old->val); |
216 | } | 216 | } |
217 | luaM_freearray(L, nold, oldsize, Node); /* free old array */ | 217 | luaM_freearray(L, nold, oldsize, Node); /* free old array */ |
218 | } | 218 | } |
@@ -243,7 +243,7 @@ static TObject *newkey (lua_State *L, Hash *t, Node *mp, const TObject *key) { | |||
243 | mp = n; | 243 | mp = n; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | mp->key = *key; | 246 | setobj(&mp->key, key); |
247 | for (;;) { /* correct `firstfree' */ | 247 | for (;;) { /* correct `firstfree' */ |
248 | if (ttype(&t->firstfree->key) == LUA_TNIL) | 248 | if (ttype(&t->firstfree->key) == LUA_TNIL) |
249 | return &mp->val; /* OK; table still has a free place */ | 249 | return &mp->val; /* OK; table still has a free place */ |
@@ -279,8 +279,7 @@ TObject *luaH_setnum (lua_State *L, Hash *t, lua_Number key) { | |||
279 | else n = n->next; | 279 | else n = n->next; |
280 | } while (n); | 280 | } while (n); |
281 | /* `key' not found; must insert it */ | 281 | /* `key' not found; must insert it */ |
282 | ttype(&kobj) = LUA_TNUMBER; | 282 | setnvalue(&kobj, key); |
283 | nvalue(&kobj) = key; | ||
284 | return newkey(L, t, mp, &kobj); | 283 | return newkey(L, t, mp, &kobj); |
285 | } | 284 | } |
286 | 285 | ||
@@ -295,8 +294,7 @@ TObject *luaH_setstr (lua_State *L, Hash *t, TString *key) { | |||
295 | else n = n->next; | 294 | else n = n->next; |
296 | } while (n); | 295 | } while (n); |
297 | /* `key' not found; must insert it */ | 296 | /* `key' not found; must insert it */ |
298 | ttype(&kobj) = LUA_TSTRING; | 297 | setsvalue(&kobj, key); |
299 | tsvalue(&kobj) = key; | ||
300 | return newkey(L, t, mp, &kobj); | 298 | return newkey(L, t, mp, &kobj); |
301 | } | 299 | } |
302 | 300 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.55 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.56 2001/01/15 16:13:24 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 | */ |
@@ -226,8 +226,7 @@ static int string_query (lua_State *L) { | |||
226 | TString *ts; | 226 | TString *ts; |
227 | int n = 0; | 227 | int n = 0; |
228 | for (ts = tb->hash[s]; ts; ts = ts->nexthash) { | 228 | for (ts = tb->hash[s]; ts; ts = ts->nexthash) { |
229 | ttype(L->top) = LUA_TSTRING; | 229 | setsvalue(L->top, ts); |
230 | tsvalue(L->top) = ts; | ||
231 | incr_top; | 230 | incr_top; |
232 | n++; | 231 | n++; |
233 | } | 232 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.58 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.59 2000/12/28 12:55:41 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 | */ |
@@ -129,11 +129,10 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | |||
129 | e = luaI_checkevent(L, event, t); | 129 | e = luaI_checkevent(L, event, t); |
130 | checktag(L, t); | 130 | checktag(L, t); |
131 | if (luaT_validevent(t, e) && luaT_gettm(L, t, e)) { | 131 | if (luaT_validevent(t, e) && luaT_gettm(L, t, e)) { |
132 | clvalue(L->top) = luaT_gettm(L, t, e); | 132 | setclvalue(L->top, luaT_gettm(L, t, e)); |
133 | ttype(L->top) = LUA_TFUNCTION; | ||
134 | } | 133 | } |
135 | else | 134 | else |
136 | ttype(L->top) = LUA_TNIL; | 135 | setnilvalue(L->top); |
137 | incr_top; | 136 | incr_top; |
138 | } | 137 | } |
139 | 138 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.152 2001/01/11 18:59:32 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.153 2001/01/15 16:13:24 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 | */ |
@@ -57,8 +57,7 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ | |||
57 | else { | 57 | else { |
58 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ | 58 | char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */ |
59 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ | 59 | lua_number2str(s, nvalue(obj)); /* convert `s' to number */ |
60 | tsvalue(obj) = luaS_new(L, s); | 60 | setsvalue(obj, luaS_new(L, s)); |
61 | ttype(obj) = LUA_TSTRING; | ||
62 | return 0; | 61 | return 0; |
63 | } | 62 | } |
64 | } | 63 | } |
@@ -89,9 +88,8 @@ static Closure *luaV_closure (lua_State *L, int nelems) { | |||
89 | Closure *c = luaF_newclosure(L, nelems); | 88 | Closure *c = luaF_newclosure(L, nelems); |
90 | L->top -= nelems; | 89 | L->top -= nelems; |
91 | while (nelems--) | 90 | while (nelems--) |
92 | c->upvalue[nelems] = *(L->top+nelems); | 91 | setobj(&c->upvalue[nelems], L->top+nelems); |
93 | clvalue(L->top) = c; | 92 | setclvalue(L->top, c); |
94 | ttype(L->top) = LUA_TFUNCTION; | ||
95 | incr_top; | 93 | incr_top; |
96 | return c; | 94 | return c; |
97 | } | 95 | } |
@@ -133,10 +131,9 @@ const TObject *luaV_gettable (lua_State *L, StkId t) { | |||
133 | } | 131 | } |
134 | if (tm != NULL) { /* is there a tag method? */ | 132 | if (tm != NULL) { /* is there a tag method? */ |
135 | luaD_checkstack(L, 2); | 133 | luaD_checkstack(L, 2); |
136 | *(L->top+1) = *(L->top-1); /* key */ | 134 | setobj(L->top+1, L->top-1); /* key */ |
137 | *L->top = *t; /* table */ | 135 | setobj(L->top, t); /* table */ |
138 | clvalue(L->top-1) = tm; /* tag method */ | 136 | setclvalue(L->top-1, tm); /* tag method */ |
139 | ttype(L->top-1) = LUA_TFUNCTION; | ||
140 | L->top += 2; | 137 | L->top += 2; |
141 | luaD_call(L, L->top - 3, 1); | 138 | luaD_call(L, L->top - 3, 1); |
142 | return L->top - 1; /* call result */ | 139 | return L->top - 1; /* call result */ |
@@ -155,17 +152,17 @@ void luaV_settable (lua_State *L, StkId t, StkId key) { | |||
155 | int tg; | 152 | int tg; |
156 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ | 153 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ |
157 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ | 154 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ |
158 | luaT_gettm(L, tg, TM_SETTABLE) == NULL)) /* or no TM? */ | 155 | luaT_gettm(L, tg, TM_SETTABLE) == NULL)) { /* or no TM? */ |
159 | *luaH_set(L, hvalue(t), key) = *(L->top-1); /* do a primitive set */ | 156 | setobj(luaH_set(L, hvalue(t), key), L->top-1); /* do a primitive set */ |
157 | } | ||
160 | else { /* try a `settable' tag method */ | 158 | else { /* try a `settable' tag method */ |
161 | Closure *tm = luaT_gettmbyObj(L, t, TM_SETTABLE); | 159 | Closure *tm = luaT_gettmbyObj(L, t, TM_SETTABLE); |
162 | if (tm != NULL) { | 160 | if (tm != NULL) { |
163 | luaD_checkstack(L, 3); | 161 | luaD_checkstack(L, 3); |
164 | *(L->top+2) = *(L->top-1); | 162 | setobj(L->top+2, L->top-1); |
165 | *(L->top+1) = *key; | 163 | setobj(L->top+1, key); |
166 | *(L->top) = *t; | 164 | setobj(L->top, t); |
167 | clvalue(L->top-1) = tm; | 165 | setclvalue(L->top-1, tm); |
168 | ttype(L->top-1) = LUA_TFUNCTION; | ||
169 | L->top += 3; | 166 | L->top += 3; |
170 | luaD_call(L, L->top - 4, 0); /* call `settable' tag method */ | 167 | luaD_call(L, L->top - 4, 0); /* call `settable' tag method */ |
171 | } | 168 | } |
@@ -182,11 +179,9 @@ const TObject *luaV_getglobal (lua_State *L, TString *s) { | |||
182 | return value; /* default behavior */ | 179 | return value; /* default behavior */ |
183 | else { /* tag method */ | 180 | else { /* tag method */ |
184 | luaD_checkstack(L, 3); | 181 | luaD_checkstack(L, 3); |
185 | clvalue(L->top) = tm; | 182 | setclvalue(L->top, tm); |
186 | ttype(L->top) = LUA_TFUNCTION; | 183 | setsvalue(L->top+1, s); /* global name */ |
187 | tsvalue(L->top+1) = s; /* global name */ | 184 | setobj(L->top+2, value); |
188 | ttype(L->top+1) = LUA_TSTRING; | ||
189 | *(L->top+2) = *value; | ||
190 | L->top += 3; | 185 | L->top += 3; |
191 | luaD_call(L, L->top - 3, 1); | 186 | luaD_call(L, L->top - 3, 1); |
192 | return L->top - 1; | 187 | return L->top - 1; |
@@ -197,16 +192,15 @@ const TObject *luaV_getglobal (lua_State *L, TString *s) { | |||
197 | void luaV_setglobal (lua_State *L, TString *s) { | 192 | void luaV_setglobal (lua_State *L, TString *s) { |
198 | TObject *oldvalue = luaH_setstr(L, L->gt, s); | 193 | TObject *oldvalue = luaH_setstr(L, L->gt, s); |
199 | Closure *tm = luaT_gettmbyObj(L, oldvalue, TM_SETGLOBAL); | 194 | Closure *tm = luaT_gettmbyObj(L, oldvalue, TM_SETGLOBAL); |
200 | if (tm == NULL) /* no tag methods? */ | 195 | if (tm == NULL) { /* no tag methods? */ |
201 | *oldvalue = *(L->top - 1); /* raw set */ | 196 | setobj(oldvalue, L->top - 1); /* raw set */ |
197 | } | ||
202 | else { /* call tag method */ | 198 | else { /* call tag method */ |
203 | luaD_checkstack(L, 3); | 199 | luaD_checkstack(L, 3); |
204 | *(L->top+2) = *(L->top-1); /* new value */ | 200 | setobj(L->top+2, L->top-1); /* new value */ |
205 | *(L->top+1) = *oldvalue; | 201 | setobj(L->top+1, oldvalue); /* old value */ |
206 | ttype(L->top) = LUA_TSTRING; | 202 | setsvalue(L->top, s); /* var name */ |
207 | tsvalue(L->top) = s; | 203 | setclvalue(L->top-1, tm); /* tag method */ |
208 | clvalue(L->top-1) = tm; | ||
209 | ttype(L->top-1) = LUA_TFUNCTION; | ||
210 | L->top += 3; | 204 | L->top += 3; |
211 | luaD_call(L, L->top - 4, 0); | 205 | luaD_call(L, L->top - 4, 0); |
212 | } | 206 | } |
@@ -266,8 +260,8 @@ int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r, StkId top) | |||
266 | return luaV_strlessthan(tsvalue(l), tsvalue(r)); | 260 | return luaV_strlessthan(tsvalue(l), tsvalue(r)); |
267 | else { /* call TM */ | 261 | else { /* call TM */ |
268 | luaD_checkstack(L, 2); | 262 | luaD_checkstack(L, 2); |
269 | *top++ = *l; | 263 | setobj(top++, l); |
270 | *top++ = *r; | 264 | setobj(top++, r); |
271 | if (!call_binTM(L, top, TM_LT)) | 265 | if (!call_binTM(L, top, TM_LT)) |
272 | luaG_ordererror(L, top-2); | 266 | luaG_ordererror(L, top-2); |
273 | L->top--; | 267 | L->top--; |
@@ -301,7 +295,7 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
301 | memcpy(buffer+tl, tsvalue(top-i)->str, l); | 295 | memcpy(buffer+tl, tsvalue(top-i)->str, l); |
302 | tl += l; | 296 | tl += l; |
303 | } | 297 | } |
304 | tsvalue(top-n) = luaS_newlstr(L, buffer, tl); | 298 | setsvalue(top-n, luaS_newlstr(L, buffer, tl)); |
305 | } | 299 | } |
306 | total -= n-1; /* got `n' strings to create 1 new */ | 300 | total -= n-1; /* got `n' strings to create 1 new */ |
307 | top -= n-1; | 301 | top -= n-1; |
@@ -310,18 +304,14 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
310 | 304 | ||
311 | 305 | ||
312 | static void luaV_pack (lua_State *L, StkId firstelem) { | 306 | static void luaV_pack (lua_State *L, StkId firstelem) { |
313 | TObject *nf; | ||
314 | int i; | 307 | int i; |
315 | Hash *htab = luaH_new(L, 0); | 308 | Hash *htab = luaH_new(L, 0); |
316 | for (i=0; firstelem+i<L->top; i++) | 309 | for (i=0; firstelem+i<L->top; i++) |
317 | *luaH_setnum(L, htab, i+1) = *(firstelem+i); | 310 | setobj(luaH_setnum(L, htab, i+1), firstelem+i); |
318 | /* store counter in field `n' */ | 311 | /* store counter in field `n' */ |
319 | nf = luaH_setstr(L, htab, luaS_newliteral(L, "n")); | 312 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), i); |
320 | ttype(nf) = LUA_TNUMBER; | ||
321 | nvalue(nf) = i; | ||
322 | L->top = firstelem; /* remove elements from the stack */ | 313 | L->top = firstelem; /* remove elements from the stack */ |
323 | ttype(L->top) = LUA_TTABLE; | 314 | sethvalue(L->top, htab); |
324 | hvalue(L->top) = htab; | ||
325 | incr_top; | 315 | incr_top; |
326 | } | 316 | } |
327 | 317 | ||
@@ -381,7 +371,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
381 | int n = GETARG_U(i); | 371 | int n = GETARG_U(i); |
382 | LUA_ASSERT(n>0, "invalid argument"); | 372 | LUA_ASSERT(n>0, "invalid argument"); |
383 | do { | 373 | do { |
384 | ttype(top++) = LUA_TNIL; | 374 | setnilvalue(top++); |
385 | } while (--n > 0); | 375 | } while (--n > 0); |
386 | break; | 376 | break; |
387 | } | 377 | } |
@@ -390,88 +380,74 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
390 | break; | 380 | break; |
391 | } | 381 | } |
392 | case OP_PUSHINT: { | 382 | case OP_PUSHINT: { |
393 | ttype(top) = LUA_TNUMBER; | 383 | setnvalue(top++, (lua_Number)GETARG_S(i)); |
394 | nvalue(top) = (lua_Number)GETARG_S(i); | ||
395 | top++; | ||
396 | break; | 384 | break; |
397 | } | 385 | } |
398 | case OP_PUSHSTRING: { | 386 | case OP_PUSHSTRING: { |
399 | ttype(top) = LUA_TSTRING; | 387 | setsvalue(top++, kstr[GETARG_U(i)]); |
400 | tsvalue(top) = kstr[GETARG_U(i)]; | ||
401 | top++; | ||
402 | break; | 388 | break; |
403 | } | 389 | } |
404 | case OP_PUSHNUM: { | 390 | case OP_PUSHNUM: { |
405 | ttype(top) = LUA_TNUMBER; | 391 | setnvalue(top++, tf->knum[GETARG_U(i)]); |
406 | nvalue(top) = tf->knum[GETARG_U(i)]; | ||
407 | top++; | ||
408 | break; | 392 | break; |
409 | } | 393 | } |
410 | case OP_PUSHNEGNUM: { | 394 | case OP_PUSHNEGNUM: { |
411 | ttype(top) = LUA_TNUMBER; | 395 | setnvalue(top++, -tf->knum[GETARG_U(i)]); |
412 | nvalue(top) = -tf->knum[GETARG_U(i)]; | ||
413 | top++; | ||
414 | break; | 396 | break; |
415 | } | 397 | } |
416 | case OP_PUSHUPVALUE: { | 398 | case OP_PUSHUPVALUE: { |
417 | *top++ = cl->upvalue[GETARG_U(i)]; | 399 | setobj(top++, &cl->upvalue[GETARG_U(i)]); |
418 | break; | 400 | break; |
419 | } | 401 | } |
420 | case OP_GETLOCAL: { | 402 | case OP_GETLOCAL: { |
421 | *top++ = *(base+GETARG_U(i)); | 403 | setobj(top++, base+GETARG_U(i)); |
422 | break; | 404 | break; |
423 | } | 405 | } |
424 | case OP_GETGLOBAL: { | 406 | case OP_GETGLOBAL: { |
425 | L->top = top; | 407 | L->top = top; |
426 | *top = *luaV_getglobal(L, kstr[GETARG_U(i)]); | 408 | setobj(top++, luaV_getglobal(L, kstr[GETARG_U(i)])); |
427 | top++; | ||
428 | break; | 409 | break; |
429 | } | 410 | } |
430 | case OP_GETTABLE: { | 411 | case OP_GETTABLE: { |
431 | L->top = top; | 412 | L->top = top; |
432 | top--; | 413 | top--; |
433 | *(top-1) = *luaV_gettable(L, top-1); | 414 | setobj(top-1, luaV_gettable(L, top-1)); |
434 | break; | 415 | break; |
435 | } | 416 | } |
436 | case OP_GETDOTTED: { | 417 | case OP_GETDOTTED: { |
437 | ttype(top) = LUA_TSTRING; | 418 | setsvalue(top, kstr[GETARG_U(i)]); |
438 | tsvalue(top) = kstr[GETARG_U(i)]; | ||
439 | L->top = top+1; | 419 | L->top = top+1; |
440 | *(top-1) = *luaV_gettable(L, top-1); | 420 | setobj(top-1, luaV_gettable(L, top-1)); |
441 | break; | 421 | break; |
442 | } | 422 | } |
443 | case OP_GETINDEXED: { | 423 | case OP_GETINDEXED: { |
444 | *top = *(base+GETARG_U(i)); | 424 | setobj(top, base+GETARG_U(i)); |
445 | L->top = top+1; | 425 | L->top = top+1; |
446 | *(top-1) = *luaV_gettable(L, top-1); | 426 | setobj(top-1, luaV_gettable(L, top-1)); |
447 | break; | 427 | break; |
448 | } | 428 | } |
449 | case OP_PUSHSELF: { | 429 | case OP_PUSHSELF: { |
450 | TObject receiver; | 430 | TObject receiver; |
451 | receiver = *(top-1); | 431 | setobj(&receiver, top-1); |
452 | ttype(top) = LUA_TSTRING; | 432 | setsvalue(top++, kstr[GETARG_U(i)]); |
453 | tsvalue(top++) = kstr[GETARG_U(i)]; | ||
454 | L->top = top; | 433 | L->top = top; |
455 | *(top-2) = *luaV_gettable(L, top-2); | 434 | setobj(top-2, luaV_gettable(L, top-2)); |
456 | *(top-1) = receiver; | 435 | setobj(top-1, &receiver); |
457 | break; | 436 | break; |
458 | } | 437 | } |
459 | case OP_CREATETABLE: { | 438 | case OP_CREATETABLE: { |
460 | L->top = top; | 439 | L->top = top; |
461 | luaC_checkGC(L); | 440 | luaC_checkGC(L); |
462 | hvalue(top) = luaH_new(L, GETARG_U(i)); | 441 | sethvalue(top++, luaH_new(L, GETARG_U(i))); |
463 | ttype(top) = LUA_TTABLE; | ||
464 | top++; | ||
465 | break; | 442 | break; |
466 | } | 443 | } |
467 | case OP_SETLOCAL: { | 444 | case OP_SETLOCAL: { |
468 | *(base+GETARG_U(i)) = *(--top); | 445 | setobj(base+GETARG_U(i), --top); |
469 | break; | 446 | break; |
470 | } | 447 | } |
471 | case OP_SETGLOBAL: { | 448 | case OP_SETGLOBAL: { |
472 | L->top = top; | 449 | L->top = top--; |
473 | luaV_setglobal(L, kstr[GETARG_U(i)]); | 450 | luaV_setglobal(L, kstr[GETARG_U(i)]); |
474 | top--; | ||
475 | break; | 451 | break; |
476 | } | 452 | } |
477 | case OP_SETTABLE: { | 453 | case OP_SETTABLE: { |
@@ -487,7 +463,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
487 | Hash *arr = hvalue(top-n-1); | 463 | Hash *arr = hvalue(top-n-1); |
488 | L->top = top-n; /* final value of `top' (in case of errors) */ | 464 | L->top = top-n; /* final value of `top' (in case of errors) */ |
489 | for (; n; n--) | 465 | for (; n; n--) |
490 | *luaH_setnum(L, arr, n+aux) = *(--top); | 466 | setobj(luaH_setnum(L, arr, n+aux), --top); |
491 | break; | 467 | break; |
492 | } | 468 | } |
493 | case OP_SETMAP: { | 469 | case OP_SETMAP: { |
@@ -497,7 +473,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
497 | L->top = finaltop; /* final value of `top' (in case of errors) */ | 473 | L->top = finaltop; /* final value of `top' (in case of errors) */ |
498 | for (; n; n--) { | 474 | for (; n; n--) { |
499 | top-=2; | 475 | top-=2; |
500 | *luaH_set(L, arr, top) = *(top+1); | 476 | setobj(luaH_set(L, arr, top), top+1); |
501 | } | 477 | } |
502 | break; | 478 | break; |
503 | } | 479 | } |
@@ -511,8 +487,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
511 | } | 487 | } |
512 | case OP_ADDI: { | 488 | case OP_ADDI: { |
513 | if (tonumber(top-1)) { | 489 | if (tonumber(top-1)) { |
514 | ttype(top) = LUA_TNUMBER; | 490 | setnvalue(top, (lua_Number)GETARG_S(i)); |
515 | nvalue(top) = (lua_Number)GETARG_S(i); | ||
516 | call_arith(L, top+1, TM_ADD); | 491 | call_arith(L, top+1, TM_ADD); |
517 | } | 492 | } |
518 | else | 493 | else |
@@ -559,7 +534,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
559 | } | 534 | } |
560 | case OP_MINUS: { | 535 | case OP_MINUS: { |
561 | if (tonumber(top-1)) { | 536 | if (tonumber(top-1)) { |
562 | ttype(top) = LUA_TNIL; | 537 | setnilvalue(top); |
563 | call_arith(L, top+1, TM_UNM); | 538 | call_arith(L, top+1, TM_UNM); |
564 | } | 539 | } |
565 | else | 540 | else |
@@ -625,7 +600,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
625 | break; | 600 | break; |
626 | } | 601 | } |
627 | case OP_PUSHNILJMP: { | 602 | case OP_PUSHNILJMP: { |
628 | ttype(top++) = LUA_TNIL; | 603 | setnilvalue(top++); |
629 | pc++; | 604 | pc++; |
630 | break; | 605 | break; |
631 | } | 606 | } |
@@ -669,8 +644,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
669 | } | 644 | } |
670 | else { | 645 | else { |
671 | top += 2; /* index,value */ | 646 | top += 2; /* index,value */ |
672 | *(top-2) = *key(node); | 647 | setobj(top-2, key(node)); |
673 | *(top-1) = *val(node); | 648 | setobj(top-1, val(node)); |
674 | } | 649 | } |
675 | break; | 650 | break; |
676 | } | 651 | } |
@@ -681,8 +656,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
681 | if (node == NULL) /* end loop? */ | 656 | if (node == NULL) /* end loop? */ |
682 | top -= 3; /* remove table, key, and value */ | 657 | top -= 3; /* remove table, key, and value */ |
683 | else { | 658 | else { |
684 | *(top-2) = *key(node); | 659 | setobj(top-2, key(node)); |
685 | *(top-1) = *val(node); | 660 | setobj(top-1, val(node)); |
686 | dojump(pc, i); /* repeat loop */ | 661 | dojump(pc, i); /* repeat loop */ |
687 | } | 662 | } |
688 | break; | 663 | break; |