diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-01-13 13:56:03 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-01-13 13:56:03 -0200 |
commit | 46ec57cbc6dfe8df707be8f1fa52146988013feb (patch) | |
tree | 9d5a08bbcc0c515f80475f30f3a6e4f933df0dd4 /lvm.c | |
parent | 62787f1b1f9bb745afbf28b04241c9020a74b7a2 (diff) | |
download | lua-46ec57cbc6dfe8df707be8f1fa52146988013feb.tar.gz lua-46ec57cbc6dfe8df707be8f1fa52146988013feb.tar.bz2 lua-46ec57cbc6dfe8df707be8f1fa52146988013feb.zip |
little change when calling tag methods
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 63 |
1 files changed, 39 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.77 1999/12/29 16:31:15 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.78 1999/12/30 18:28:40 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 | */ |
@@ -33,8 +33,11 @@ | |||
33 | #define highbyte(L, x) ((x)<<8) | 33 | #define highbyte(L, x) ((x)<<8) |
34 | 34 | ||
35 | 35 | ||
36 | /* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */ | 36 | /* |
37 | #define EXTRA_STACK 6 | 37 | ** Extra stack size to run a function: |
38 | ** LUA_T_LINE(1), NAME(1), TM calls(3) (plus some extra...) | ||
39 | */ | ||
40 | #define EXTRA_STACK 8 | ||
38 | 41 | ||
39 | 42 | ||
40 | 43 | ||
@@ -133,6 +136,7 @@ void luaV_gettable (lua_State *L) { | |||
133 | 136 | ||
134 | /* | 137 | /* |
135 | ** Receives table at *t, index at *(t+1) and value at top. | 138 | ** Receives table at *t, index at *(t+1) and value at top. |
139 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) | ||
136 | */ | 140 | */ |
137 | void luaV_settable (lua_State *L, StkId t) { | 141 | void luaV_settable (lua_State *L, StkId t) { |
138 | const TObject *im; | 142 | const TObject *im; |
@@ -152,11 +156,12 @@ void luaV_settable (lua_State *L, StkId t) { | |||
152 | } | 156 | } |
153 | /* object is not a table, or it has a `settable' method */ | 157 | /* object is not a table, or it has a `settable' method */ |
154 | /* prepare arguments and call the tag method */ | 158 | /* prepare arguments and call the tag method */ |
155 | *(L->top+1) = *(L->top-1); | 159 | *(L->top+2) = *(L->top-1); |
156 | *(L->top) = *(t+1); | 160 | *(L->top+1) = *(t+1); |
157 | *(L->top-1) = *t; | 161 | *(L->top) = *t; |
158 | L->top += 2; /* WARNING: caller must assure stack space */ | 162 | *(L->top-1) = *im; |
159 | luaD_callTM(L, im, 3, 0); | 163 | L->top += 3; |
164 | luaD_call(L, L->top-4, 0); | ||
160 | } | 165 | } |
161 | 166 | ||
162 | 167 | ||
@@ -170,36 +175,41 @@ void luaV_rawsettable (lua_State *L, StkId t) { | |||
170 | } | 175 | } |
171 | 176 | ||
172 | 177 | ||
178 | /* | ||
179 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) | ||
180 | */ | ||
173 | void luaV_getglobal (lua_State *L, GlobalVar *gv) { | 181 | void luaV_getglobal (lua_State *L, GlobalVar *gv) { |
174 | /* WARNING: caller must assure stack space */ | ||
175 | const TObject *value = &gv->value; | 182 | const TObject *value = &gv->value; |
176 | TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); | 183 | TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); |
177 | if (ttype(im) != LUA_T_NIL) { /* is there a tag method? */ | 184 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
178 | ttype(L->top) = LUA_T_STRING; | ||
179 | tsvalue(L->top) = gv->name; /* global name */ | ||
180 | L->top++; | ||
181 | *L->top++ = *value; | ||
182 | luaD_callTM(L, im, 2, 1); | ||
183 | } else { /* no tag method */ | ||
184 | *L->top++ = *value; /* default behavior */ | 185 | *L->top++ = *value; /* default behavior */ |
186 | else { /* tag method */ | ||
187 | *L->top = *im; | ||
188 | ttype(L->top+1) = LUA_T_STRING; | ||
189 | tsvalue(L->top+1) = gv->name; /* global name */ | ||
190 | *(L->top+2) = *value; | ||
191 | L->top += 3; | ||
192 | luaD_call(L, L->top-3, 1); | ||
185 | } | 193 | } |
186 | } | 194 | } |
187 | 195 | ||
188 | 196 | ||
197 | /* | ||
198 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) | ||
199 | */ | ||
189 | void luaV_setglobal (lua_State *L, GlobalVar *gv) { | 200 | void luaV_setglobal (lua_State *L, GlobalVar *gv) { |
190 | const TObject *oldvalue = &gv->value; | 201 | const TObject *oldvalue = &gv->value; |
191 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); | 202 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); |
192 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ | 203 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
193 | gv->value = *(--L->top); | 204 | gv->value = *(--L->top); |
194 | else { | 205 | else { |
195 | /* WARNING: caller must assure stack space */ | 206 | *(L->top+2) = *(L->top-1); /* new value */ |
196 | TObject newvalue; | 207 | *(L->top+1) = *oldvalue; |
197 | newvalue = *(L->top-1); | 208 | ttype(L->top) = LUA_T_STRING; |
198 | ttype(L->top-1) = LUA_T_STRING; | 209 | tsvalue(L->top) = gv->name; |
199 | tsvalue(L->top-1) = gv->name; | 210 | *(L->top-1) = *im; |
200 | *L->top++ = *oldvalue; | 211 | L->top += 3; |
201 | *L->top++ = newvalue; | 212 | luaD_call(L, L->top-4, 0); |
202 | luaD_callTM(L, im, 3, 0); | ||
203 | } | 213 | } |
204 | } | 214 | } |
205 | 215 | ||
@@ -372,12 +382,14 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
372 | L->top = top; | 382 | L->top = top; |
373 | luaV_getglobal(L, tsvalue(&consts[aux])->u.s.gv); | 383 | luaV_getglobal(L, tsvalue(&consts[aux])->u.s.gv); |
374 | top++; | 384 | top++; |
385 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
375 | break; | 386 | break; |
376 | 387 | ||
377 | case GETTABLE: | 388 | case GETTABLE: |
378 | L->top = top; | 389 | L->top = top; |
379 | luaV_gettable(L); | 390 | luaV_gettable(L); |
380 | top--; | 391 | top--; |
392 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
381 | break; | 393 | break; |
382 | 394 | ||
383 | case GETDOTTEDW: aux += highbyte(L, *pc++); | 395 | case GETDOTTEDW: aux += highbyte(L, *pc++); |
@@ -386,6 +398,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
386 | L->top = top; | 398 | L->top = top; |
387 | luaV_gettable(L); | 399 | luaV_gettable(L); |
388 | top--; | 400 | top--; |
401 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
389 | break; | 402 | break; |
390 | 403 | ||
391 | case PUSHSELFW: aux += highbyte(L, *pc++); | 404 | case PUSHSELFW: aux += highbyte(L, *pc++); |
@@ -417,6 +430,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
417 | L->top = top; | 430 | L->top = top; |
418 | luaV_setglobal(L, tsvalue(&consts[aux])->u.s.gv); | 431 | luaV_setglobal(L, tsvalue(&consts[aux])->u.s.gv); |
419 | top--; | 432 | top--; |
433 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
420 | break; | 434 | break; |
421 | 435 | ||
422 | case SETTABLEPOP: | 436 | case SETTABLEPOP: |
@@ -429,6 +443,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
429 | L->top = top; | 443 | L->top = top; |
430 | luaV_settable(L, top-3-(*pc++)); | 444 | luaV_settable(L, top-3-(*pc++)); |
431 | top--; /* pop value */ | 445 | top--; /* pop value */ |
446 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
432 | break; | 447 | break; |
433 | 448 | ||
434 | case SETLISTW: aux += highbyte(L, *pc++); | 449 | case SETLISTW: aux += highbyte(L, *pc++); |