diff options
| -rw-r--r-- | lapi.c | 14 | ||||
| -rw-r--r-- | lvm.c | 96 | ||||
| -rw-r--r-- | lvm.h | 10 |
3 files changed, 56 insertions, 64 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.68 2000/01/13 15:56:03 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.69 2000/01/19 12:00:45 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 | */ |
| @@ -123,7 +123,7 @@ lua_Object lua_seterrormethod (lua_State *L) { | |||
| 123 | 123 | ||
| 124 | lua_Object lua_gettable (lua_State *L) { | 124 | lua_Object lua_gettable (lua_State *L) { |
| 125 | luaA_checkCparams(L, 2); | 125 | luaA_checkCparams(L, 2); |
| 126 | luaV_gettable(L); | 126 | luaV_gettable(L, L->top--); |
| 127 | return luaA_putObjectOnTop(L); | 127 | return luaA_putObjectOnTop(L); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| @@ -139,10 +139,12 @@ lua_Object lua_rawgettable (lua_State *L) { | |||
| 139 | 139 | ||
| 140 | 140 | ||
| 141 | void lua_settable (lua_State *L) { | 141 | void lua_settable (lua_State *L) { |
| 142 | StkId top; | ||
| 142 | luaA_checkCparams(L, 3); | 143 | luaA_checkCparams(L, 3); |
| 143 | luaD_checkstack(L, 3); /* may need that to call a tag method */ | 144 | luaD_checkstack(L, 3); /* may need that to call a tag method */ |
| 144 | luaV_settable(L, L->top-3); | 145 | top = L->top; |
| 145 | L->top -= 2; /* pop table and index */ | 146 | luaV_settable(L, top-3, top); |
| 147 | L->top = top-3; /* pop table, index, and value */ | ||
| 146 | } | 148 | } |
| 147 | 149 | ||
| 148 | 150 | ||
| @@ -163,7 +165,7 @@ lua_Object lua_createtable (lua_State *L) { | |||
| 163 | 165 | ||
| 164 | lua_Object lua_getglobal (lua_State *L, const char *name) { | 166 | lua_Object lua_getglobal (lua_State *L, const char *name) { |
| 165 | luaD_checkstack(L, 3); /* may need that to call a tag method */ | 167 | luaD_checkstack(L, 3); /* may need that to call a tag method */ |
| 166 | luaV_getglobal(L, luaS_assertglobalbyname(L, name)); | 168 | luaV_getglobal(L, luaS_assertglobalbyname(L, name), L->top++); |
| 167 | return luaA_putObjectOnTop(L); | 169 | return luaA_putObjectOnTop(L); |
| 168 | } | 170 | } |
| 169 | 171 | ||
| @@ -177,7 +179,7 @@ lua_Object lua_rawgetglobal (lua_State *L, const char *name) { | |||
| 177 | void lua_setglobal (lua_State *L, const char *name) { | 179 | void lua_setglobal (lua_State *L, const char *name) { |
| 178 | luaA_checkCparams(L, 1); | 180 | luaA_checkCparams(L, 1); |
| 179 | luaD_checkstack(L, 3); /* may need that to call a tag method */ | 181 | luaD_checkstack(L, 3); /* may need that to call a tag method */ |
| 180 | luaV_setglobal(L, luaS_assertglobalbyname(L, name)); | 182 | luaV_setglobal(L, luaS_assertglobalbyname(L, name), L->top--); |
| 181 | } | 183 | } |
| 182 | 184 | ||
| 183 | 185 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.80 2000/01/19 12:00:45 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.81 2000/01/19 16:50:30 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 | */ |
| @@ -103,13 +103,15 @@ void luaV_closure (lua_State *L, int nelems) { | |||
| 103 | ** Function to index a table. | 103 | ** Function to index a table. |
| 104 | ** Receives the table at top-2 and the index at top-1. | 104 | ** Receives the table at top-2 and the index at top-1. |
| 105 | */ | 105 | */ |
| 106 | void luaV_gettable (lua_State *L) { | 106 | void luaV_gettable (lua_State *L, StkId top) { |
| 107 | TObject *table = L->top-2; | 107 | TObject *table = top-2; |
| 108 | const TObject *im; | 108 | const TObject *im; |
| 109 | if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ | 109 | if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */ |
| 110 | im = luaT_getimbyObj(L, table, IM_GETTABLE); | 110 | im = luaT_getimbyObj(L, table, IM_GETTABLE); |
| 111 | if (ttype(im) == LUA_T_NIL) | 111 | if (ttype(im) == LUA_T_NIL) { |
| 112 | L->top = top; | ||
| 112 | luaG_indexerror(L, table); | 113 | luaG_indexerror(L, table); |
| 114 | } | ||
| 113 | } | 115 | } |
| 114 | else { /* object is a table... */ | 116 | else { /* object is a table... */ |
| 115 | int tg = table->value.a->htag; | 117 | int tg = table->value.a->htag; |
| @@ -119,28 +121,29 @@ void luaV_gettable (lua_State *L) { | |||
| 119 | if (ttype(h) == LUA_T_NIL && | 121 | if (ttype(h) == LUA_T_NIL && |
| 120 | (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) { | 122 | (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) { |
| 121 | /* result is nil and there is an `index' tag method */ | 123 | /* result is nil and there is an `index' tag method */ |
| 124 | L->top = top; | ||
| 122 | luaD_callTM(L, im, 2, 1); /* calls it */ | 125 | luaD_callTM(L, im, 2, 1); /* calls it */ |
| 123 | } | 126 | } |
| 124 | else { | 127 | else |
| 125 | L->top--; | ||
| 126 | *table = *h; /* `push' result into table position */ | 128 | *table = *h; /* `push' result into table position */ |
| 127 | } | ||
| 128 | return; | 129 | return; |
| 129 | } | 130 | } |
| 130 | /* else it has a `gettable' method, go through to next command */ | 131 | /* else it has a `gettable' method, go through to next command */ |
| 131 | } | 132 | } |
| 132 | /* object is not a table, or it has a `gettable' method */ | 133 | /* object is not a table, or it has a `gettable' method */ |
| 134 | L->top = top; | ||
| 133 | luaD_callTM(L, im, 2, 1); | 135 | luaD_callTM(L, im, 2, 1); |
| 134 | } | 136 | } |
| 135 | 137 | ||
| 136 | 138 | ||
| 137 | /* | 139 | /* |
| 138 | ** Receives table at *t, index at *(t+1) and value at top. | 140 | ** 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) | 141 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) |
| 140 | */ | 142 | */ |
| 141 | void luaV_settable (lua_State *L, StkId t) { | 143 | void luaV_settable (lua_State *L, StkId t, StkId top) { |
| 142 | const TObject *im; | 144 | const TObject *im; |
| 143 | if (ttype(t) != LUA_T_ARRAY) { /* not a table, get `settable' method */ | 145 | if (ttype(t) != LUA_T_ARRAY) { /* not a table, get `settable' method */ |
| 146 | L->top = top; | ||
| 144 | im = luaT_getimbyObj(L, t, IM_SETTABLE); | 147 | im = luaT_getimbyObj(L, t, IM_SETTABLE); |
| 145 | if (ttype(im) == LUA_T_NIL) | 148 | if (ttype(im) == LUA_T_NIL) |
| 146 | luaG_indexerror(L, t); | 149 | luaG_indexerror(L, t); |
| @@ -148,20 +151,19 @@ void luaV_settable (lua_State *L, StkId t) { | |||
| 148 | else { /* object is a table... */ | 151 | else { /* object is a table... */ |
| 149 | im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE); | 152 | im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE); |
| 150 | if (ttype(im) == LUA_T_NIL) { /* and does not have a `settable' method */ | 153 | if (ttype(im) == LUA_T_NIL) { /* and does not have a `settable' method */ |
| 151 | luaH_set(L, avalue(t), t+1, L->top-1); | 154 | luaH_set(L, avalue(t), t+1, top-1); |
| 152 | L->top--; /* pop value */ | ||
| 153 | return; | 155 | return; |
| 154 | } | 156 | } |
| 155 | /* else it has a `settable' method, go through to next command */ | 157 | /* else it has a `settable' method, go through to next command */ |
| 156 | } | 158 | } |
| 157 | /* object is not a table, or it has a `settable' method */ | 159 | /* object is not a table, or it has a `settable' method */ |
| 158 | /* prepare arguments and call the tag method */ | 160 | /* prepare arguments and call the tag method */ |
| 159 | *(L->top+2) = *(L->top-1); | 161 | *(top+2) = *(top-1); |
| 160 | *(L->top+1) = *(t+1); | 162 | *(top+1) = *(t+1); |
| 161 | *(L->top) = *t; | 163 | *(top) = *t; |
| 162 | *(L->top-1) = *im; | 164 | *(top-1) = *im; |
| 163 | L->top += 3; | 165 | L->top = top+3; |
| 164 | luaD_call(L, L->top-4, 0); | 166 | luaD_call(L, top-1, 0); |
| 165 | } | 167 | } |
| 166 | 168 | ||
| 167 | 169 | ||
| @@ -178,18 +180,18 @@ void luaV_rawsettable (lua_State *L, StkId t) { | |||
| 178 | /* | 180 | /* |
| 179 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) | 181 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) |
| 180 | */ | 182 | */ |
| 181 | void luaV_getglobal (lua_State *L, GlobalVar *gv) { | 183 | void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) { |
| 182 | const TObject *value = &gv->value; | 184 | const TObject *value = &gv->value; |
| 183 | TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); | 185 | TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL); |
| 184 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ | 186 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
| 185 | *L->top++ = *value; /* default behavior */ | 187 | *top = *value; /* default behavior */ |
| 186 | else { /* tag method */ | 188 | else { /* tag method */ |
| 187 | *L->top = *im; | 189 | *top = *im; |
| 188 | ttype(L->top+1) = LUA_T_STRING; | 190 | ttype(top+1) = LUA_T_STRING; |
| 189 | tsvalue(L->top+1) = gv->name; /* global name */ | 191 | tsvalue(top+1) = gv->name; /* global name */ |
| 190 | *(L->top+2) = *value; | 192 | *(top+2) = *value; |
| 191 | L->top += 3; | 193 | L->top = top+3; |
| 192 | luaD_call(L, L->top-3, 1); | 194 | luaD_call(L, top, 1); |
| 193 | } | 195 | } |
| 194 | } | 196 | } |
| 195 | 197 | ||
| @@ -197,19 +199,19 @@ void luaV_getglobal (lua_State *L, GlobalVar *gv) { | |||
| 197 | /* | 199 | /* |
| 198 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) | 200 | ** WARNING: caller must assure 3 extra stack slots (to call a tag method) |
| 199 | */ | 201 | */ |
| 200 | void luaV_setglobal (lua_State *L, GlobalVar *gv) { | 202 | void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top) { |
| 201 | const TObject *oldvalue = &gv->value; | 203 | const TObject *oldvalue = &gv->value; |
| 202 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); | 204 | const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL); |
| 203 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ | 205 | if (ttype(im) == LUA_T_NIL) /* is there a tag method? */ |
| 204 | gv->value = *(--L->top); | 206 | gv->value = *(top-1); |
| 205 | else { | 207 | else { |
| 206 | *(L->top+2) = *(L->top-1); /* new value */ | 208 | *(top+2) = *(top-1); /* new value */ |
| 207 | *(L->top+1) = *oldvalue; | 209 | *(top+1) = *oldvalue; |
| 208 | ttype(L->top) = LUA_T_STRING; | 210 | ttype(top) = LUA_T_STRING; |
| 209 | tsvalue(L->top) = gv->name; | 211 | tsvalue(top) = gv->name; |
| 210 | *(L->top-1) = *im; | 212 | *(top-1) = *im; |
| 211 | L->top += 3; | 213 | L->top = top+3; |
| 212 | luaD_call(L, L->top-4, 0); | 214 | luaD_call(L, top-1, 0); |
| 213 | } | 215 | } |
| 214 | } | 216 | } |
| 215 | 217 | ||
| @@ -385,18 +387,14 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
| 385 | 387 | ||
| 386 | case GETGLOBALW: aux += highbyte(L, *pc++); | 388 | case GETGLOBALW: aux += highbyte(L, *pc++); |
| 387 | case GETGLOBAL: aux += *pc++; | 389 | case GETGLOBAL: aux += *pc++; |
| 388 | L->top = top; | ||
| 389 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); | 390 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); |
| 390 | luaV_getglobal(L, tsvalue(&consts[aux])->u.s.gv); | 391 | luaV_getglobal(L, tsvalue(&consts[aux])->u.s.gv, top); |
| 391 | top++; | 392 | top++; |
| 392 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
| 393 | break; | 393 | break; |
| 394 | 394 | ||
| 395 | case GETTABLE: | 395 | case GETTABLE: |
| 396 | L->top = top; | 396 | luaV_gettable(L, top); |
| 397 | luaV_gettable(L); | ||
| 398 | top--; | 397 | top--; |
| 399 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
| 400 | break; | 398 | break; |
| 401 | 399 | ||
| 402 | case GETDOTTEDW: aux += highbyte(L, *pc++); | 400 | case GETDOTTEDW: aux += highbyte(L, *pc++); |
| @@ -404,10 +402,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
| 404 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); | 402 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); |
| 405 | ttype(top) = LUA_T_STRING; | 403 | ttype(top) = LUA_T_STRING; |
| 406 | tsvalue(top++) = tsvalue(&consts[aux]); | 404 | tsvalue(top++) = tsvalue(&consts[aux]); |
| 407 | L->top = top; | 405 | luaV_gettable(L, top); |
| 408 | luaV_gettable(L); | ||
| 409 | top--; | 406 | top--; |
| 410 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
| 411 | break; | 407 | break; |
| 412 | 408 | ||
| 413 | case PUSHSELFW: aux += highbyte(L, *pc++); | 409 | case PUSHSELFW: aux += highbyte(L, *pc++); |
| @@ -417,8 +413,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
| 417 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); | 413 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); |
| 418 | ttype(top) = LUA_T_STRING; | 414 | ttype(top) = LUA_T_STRING; |
| 419 | tsvalue(top++) = tsvalue(&consts[aux]); | 415 | tsvalue(top++) = tsvalue(&consts[aux]); |
| 420 | L->top = top; | 416 | luaV_gettable(L, top); |
| 421 | luaV_gettable(L); | ||
| 422 | *(top-1) = receiver; | 417 | *(top-1) = receiver; |
| 423 | break; | 418 | break; |
| 424 | } | 419 | } |
| @@ -439,23 +434,18 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, | |||
| 439 | case SETGLOBALW: aux += highbyte(L, *pc++); | 434 | case SETGLOBALW: aux += highbyte(L, *pc++); |
| 440 | case SETGLOBAL: aux += *pc++; | 435 | case SETGLOBAL: aux += *pc++; |
| 441 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); | 436 | LUA_ASSERT(L, ttype(&consts[aux]) == LUA_T_STRING, "unexpected type"); |
| 442 | L->top = top; | 437 | luaV_setglobal(L, tsvalue(&consts[aux])->u.s.gv, top); |
| 443 | luaV_setglobal(L, tsvalue(&consts[aux])->u.s.gv); | ||
| 444 | top--; | 438 | top--; |
| 445 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
| 446 | break; | 439 | break; |
| 447 | 440 | ||
| 448 | case SETTABLEPOP: | 441 | case SETTABLEPOP: |
| 449 | L->top = top; | 442 | luaV_settable(L, top-3, top); |
| 450 | luaV_settable(L, top-3); | ||
| 451 | top -= 3; /* pop table, index, and value */ | 443 | top -= 3; /* pop table, index, and value */ |
| 452 | break; | 444 | break; |
| 453 | 445 | ||
| 454 | case SETTABLE: | 446 | case SETTABLE: |
| 455 | L->top = top; | 447 | luaV_settable(L, top-3-(*pc++), top); |
| 456 | luaV_settable(L, top-3-(*pc++)); | ||
| 457 | top--; /* pop value */ | 448 | top--; /* pop value */ |
| 458 | LUA_ASSERT(L, top==L->top, "top's not synchronized"); | ||
| 459 | break; | 449 | break; |
| 460 | 450 | ||
| 461 | case SETLISTW: aux += highbyte(L, *pc++); | 451 | case SETLISTW: aux += highbyte(L, *pc++); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.h,v 1.13 1999/12/01 19:50:08 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 1.14 2000/01/19 16:50:30 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 | */ |
| @@ -21,11 +21,11 @@ void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab); | |||
| 21 | int luaV_tonumber (TObject *obj); | 21 | int luaV_tonumber (TObject *obj); |
| 22 | int luaV_tostring (lua_State *L, TObject *obj); | 22 | int luaV_tostring (lua_State *L, TObject *obj); |
| 23 | void luaV_setn (lua_State *L, Hash *t, int val); | 23 | void luaV_setn (lua_State *L, Hash *t, int val); |
| 24 | void luaV_gettable (lua_State *L); | 24 | void luaV_gettable (lua_State *L, StkId top); |
| 25 | void luaV_settable (lua_State *L, StkId t); | 25 | void luaV_settable (lua_State *L, StkId t, StkId top); |
| 26 | void luaV_rawsettable (lua_State *L, StkId t); | 26 | void luaV_rawsettable (lua_State *L, StkId t); |
| 27 | void luaV_getglobal (lua_State *L, GlobalVar *gv); | 27 | void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top); |
| 28 | void luaV_setglobal (lua_State *L, GlobalVar *gv); | 28 | void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top); |
| 29 | StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId base); | 29 | StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, StkId base); |
| 30 | void luaV_closure (lua_State *L, int nelems); | 30 | void luaV_closure (lua_State *L, int nelems); |
| 31 | void luaV_comparison (lua_State *L); | 31 | void luaV_comparison (lua_State *L); |
