diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-29 12:06:44 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-29 12:06:44 -0300 |
| commit | f96497397addca22f22a6ba6eeabc906be43f16b (patch) | |
| tree | af8d27b9af36dfe0b0b6e0f765ea90b95b110efc | |
| parent | 5a1c8d8ef343bf0157851a4832c2c937b812b64f (diff) | |
| download | lua-f96497397addca22f22a6ba6eeabc906be43f16b.tar.gz lua-f96497397addca22f22a6ba6eeabc906be43f16b.tar.bz2 lua-f96497397addca22f22a6ba6eeabc906be43f16b.zip | |
new type 'StackValue' for stack elements
(we may want to put extra info there in the future)
| -rw-r--r-- | lapi.c | 268 | ||||
| -rw-r--r-- | lcode.c | 4 | ||||
| -rw-r--r-- | ldebug.c | 30 | ||||
| -rw-r--r-- | ldo.c | 38 | ||||
| -rw-r--r-- | ldo.h | 4 | ||||
| -rw-r--r-- | lfunc.c | 12 | ||||
| -rw-r--r-- | lfunc.h | 5 | ||||
| -rw-r--r-- | lgc.c | 10 | ||||
| -rw-r--r-- | llex.c | 4 | ||||
| -rw-r--r-- | lobject.c | 45 | ||||
| -rw-r--r-- | lobject.h | 33 | ||||
| -rw-r--r-- | lparser.c | 6 | ||||
| -rw-r--r-- | lstate.c | 10 | ||||
| -rw-r--r-- | ltable.c | 12 | ||||
| -rw-r--r-- | ltests.c | 8 | ||||
| -rw-r--r-- | ltm.c | 46 | ||||
| -rw-r--r-- | ltm.h | 8 | ||||
| -rw-r--r-- | lundump.c | 4 | ||||
| -rw-r--r-- | lvm.c | 209 | ||||
| -rw-r--r-- | lvm.h | 4 |
20 files changed, 409 insertions, 351 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.268 2017/05/26 19:14:29 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.269 2017/06/01 20:22:33 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 | */ |
| @@ -57,33 +57,48 @@ const char lua_ident[] = | |||
| 57 | api_check(l, isstackindex(i, o), "index not in the stack") | 57 | api_check(l, isstackindex(i, o), "index not in the stack") |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | static TValue *index2addr (lua_State *L, int idx) { | 60 | static TValue *index2value (lua_State *L, int idx) { |
| 61 | CallInfo *ci = L->ci; | 61 | CallInfo *ci = L->ci; |
| 62 | if (idx > 0) { | 62 | if (idx > 0) { |
| 63 | TValue *o = ci->func + idx; | 63 | StkId o = ci->func + idx; |
| 64 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); | 64 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); |
| 65 | if (o >= L->top) return NONVALIDVALUE; | 65 | if (o >= L->top) return NONVALIDVALUE; |
| 66 | else return o; | 66 | else return s2v(o); |
| 67 | } | 67 | } |
| 68 | else if (!ispseudo(idx)) { /* negative index */ | 68 | else if (!ispseudo(idx)) { /* negative index */ |
| 69 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | 69 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); |
| 70 | return L->top + idx; | 70 | return s2v(L->top + idx); |
| 71 | } | 71 | } |
| 72 | else if (idx == LUA_REGISTRYINDEX) | 72 | else if (idx == LUA_REGISTRYINDEX) |
| 73 | return &G(L)->l_registry; | 73 | return &G(L)->l_registry; |
| 74 | else { /* upvalues */ | 74 | else { /* upvalues */ |
| 75 | idx = LUA_REGISTRYINDEX - idx; | 75 | idx = LUA_REGISTRYINDEX - idx; |
| 76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); | 76 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); |
| 77 | if (ttislcf(ci->func)) /* light C function? */ | 77 | if (ttislcf(s2v(ci->func))) /* light C function? */ |
| 78 | return NONVALIDVALUE; /* it has no upvalues */ | 78 | return NONVALIDVALUE; /* it has no upvalues */ |
| 79 | else { | 79 | else { |
| 80 | CClosure *func = clCvalue(ci->func); | 80 | CClosure *func = clCvalue(s2v(ci->func)); |
| 81 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; | 81 | return (idx <= func->nupvalues) ? &func->upvalue[idx-1] : NONVALIDVALUE; |
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | static StkId index2stack (lua_State *L, int idx) { | ||
| 88 | CallInfo *ci = L->ci; | ||
| 89 | if (idx > 0) { | ||
| 90 | StkId o = ci->func + idx; | ||
| 91 | api_check(L, o < L->top, "unacceptable index"); | ||
| 92 | return o; | ||
| 93 | } | ||
| 94 | else { /* non-positive index */ | ||
| 95 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | ||
| 96 | api_check(L, !ispseudo(idx), "invalid index"); | ||
| 97 | return L->top + idx; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | |||
| 87 | /* | 102 | /* |
| 88 | ** to be called by 'lua_checkstack' in protected mode, to grow stack | 103 | ** to be called by 'lua_checkstack' in protected mode, to grow stack |
| 89 | ** capturing memory errors | 104 | ** capturing memory errors |
| @@ -124,7 +139,7 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { | |||
| 124 | api_check(from, to->ci->top - to->top >= n, "stack overflow"); | 139 | api_check(from, to->ci->top - to->top >= n, "stack overflow"); |
| 125 | from->top -= n; | 140 | from->top -= n; |
| 126 | for (i = 0; i < n; i++) { | 141 | for (i = 0; i < n; i++) { |
| 127 | setobj2s(to, to->top, from->top + i); | 142 | setobjs2s(to, to->top, from->top + i); |
| 128 | to->top++; /* stack already checked by previous 'api_check' */ | 143 | to->top++; /* stack already checked by previous 'api_check' */ |
| 129 | } | 144 | } |
| 130 | lua_unlock(to); | 145 | lua_unlock(to); |
| @@ -175,7 +190,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
| 175 | if (idx >= 0) { | 190 | if (idx >= 0) { |
| 176 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); | 191 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); |
| 177 | while (L->top < (func + 1) + idx) | 192 | while (L->top < (func + 1) + idx) |
| 178 | setnilvalue(L->top++); | 193 | setnilvalue(s2v(L->top++)); |
| 179 | L->top = (func + 1) + idx; | 194 | L->top = (func + 1) + idx; |
| 180 | } | 195 | } |
| 181 | else { | 196 | else { |
| @@ -189,11 +204,13 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
| 189 | /* | 204 | /* |
| 190 | ** Reverse the stack segment from 'from' to 'to' | 205 | ** Reverse the stack segment from 'from' to 'to' |
| 191 | ** (auxiliary to 'lua_rotate') | 206 | ** (auxiliary to 'lua_rotate') |
| 207 | ** Note that we move(copy) only the value inside the stack. | ||
| 208 | ** (We do not move addicional fields that may exist.) | ||
| 192 | */ | 209 | */ |
| 193 | static void reverse (lua_State *L, StkId from, StkId to) { | 210 | static void reverse (lua_State *L, StkId from, StkId to) { |
| 194 | for (; from < to; from++, to--) { | 211 | for (; from < to; from++, to--) { |
| 195 | TValue temp; | 212 | TValue temp; |
| 196 | setobj(L, &temp, from); | 213 | setobj(L, &temp, s2v(from)); |
| 197 | setobjs2s(L, from, to); | 214 | setobjs2s(L, from, to); |
| 198 | setobj2s(L, to, &temp); | 215 | setobj2s(L, to, &temp); |
| 199 | } | 216 | } |
| @@ -208,8 +225,7 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { | |||
| 208 | StkId p, t, m; | 225 | StkId p, t, m; |
| 209 | lua_lock(L); | 226 | lua_lock(L); |
| 210 | t = L->top - 1; /* end of stack segment being rotated */ | 227 | t = L->top - 1; /* end of stack segment being rotated */ |
| 211 | p = index2addr(L, idx); /* start of segment */ | 228 | p = index2stack(L, idx); /* start of segment */ |
| 212 | api_checkstackindex(L, idx, p); | ||
| 213 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); | 229 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); |
| 214 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ | 230 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ |
| 215 | reverse(L, p, m); /* reverse the prefix with length 'n' */ | 231 | reverse(L, p, m); /* reverse the prefix with length 'n' */ |
| @@ -222,12 +238,12 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { | |||
| 222 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | 238 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { |
| 223 | TValue *fr, *to; | 239 | TValue *fr, *to; |
| 224 | lua_lock(L); | 240 | lua_lock(L); |
| 225 | fr = index2addr(L, fromidx); | 241 | fr = index2value(L, fromidx); |
| 226 | to = index2addr(L, toidx); | 242 | to = index2value(L, toidx); |
| 227 | api_checkvalidindex(L, to); | 243 | api_checkvalidindex(L, to); |
| 228 | setobj(L, to, fr); | 244 | setobj(L, to, fr); |
| 229 | if (isupvalue(toidx)) /* function upvalue? */ | 245 | if (isupvalue(toidx)) /* function upvalue? */ |
| 230 | luaC_barrier(L, clCvalue(L->ci->func), fr); | 246 | luaC_barrier(L, clCvalue(s2v(L->ci->func)), fr); |
| 231 | /* LUA_REGISTRYINDEX does not need gc barrier | 247 | /* LUA_REGISTRYINDEX does not need gc barrier |
| 232 | (collector revisits it before finishing collection) */ | 248 | (collector revisits it before finishing collection) */ |
| 233 | lua_unlock(L); | 249 | lua_unlock(L); |
| @@ -236,7 +252,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | |||
| 236 | 252 | ||
| 237 | LUA_API void lua_pushvalue (lua_State *L, int idx) { | 253 | LUA_API void lua_pushvalue (lua_State *L, int idx) { |
| 238 | lua_lock(L); | 254 | lua_lock(L); |
| 239 | setobj2s(L, L->top, index2addr(L, idx)); | 255 | setobj2s(L, L->top, index2value(L, idx)); |
| 240 | api_incr_top(L); | 256 | api_incr_top(L); |
| 241 | lua_unlock(L); | 257 | lua_unlock(L); |
| 242 | } | 258 | } |
| @@ -249,7 +265,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) { | |||
| 249 | 265 | ||
| 250 | 266 | ||
| 251 | LUA_API int lua_type (lua_State *L, int idx) { | 267 | LUA_API int lua_type (lua_State *L, int idx) { |
| 252 | StkId o = index2addr(L, idx); | 268 | const TValue *o = index2value(L, idx); |
| 253 | return (isvalid(o) ? ttnov(o) : LUA_TNONE); | 269 | return (isvalid(o) ? ttnov(o) : LUA_TNONE); |
| 254 | } | 270 | } |
| 255 | 271 | ||
| @@ -262,39 +278,39 @@ LUA_API const char *lua_typename (lua_State *L, int t) { | |||
| 262 | 278 | ||
| 263 | 279 | ||
| 264 | LUA_API int lua_iscfunction (lua_State *L, int idx) { | 280 | LUA_API int lua_iscfunction (lua_State *L, int idx) { |
| 265 | StkId o = index2addr(L, idx); | 281 | const TValue *o = index2value(L, idx); |
| 266 | return (ttislcf(o) || (ttisCclosure(o))); | 282 | return (ttislcf(o) || (ttisCclosure(o))); |
| 267 | } | 283 | } |
| 268 | 284 | ||
| 269 | 285 | ||
| 270 | LUA_API int lua_isinteger (lua_State *L, int idx) { | 286 | LUA_API int lua_isinteger (lua_State *L, int idx) { |
| 271 | StkId o = index2addr(L, idx); | 287 | const TValue *o = index2value(L, idx); |
| 272 | return ttisinteger(o); | 288 | return ttisinteger(o); |
| 273 | } | 289 | } |
| 274 | 290 | ||
| 275 | 291 | ||
| 276 | LUA_API int lua_isnumber (lua_State *L, int idx) { | 292 | LUA_API int lua_isnumber (lua_State *L, int idx) { |
| 277 | lua_Number n; | 293 | lua_Number n; |
| 278 | const TValue *o = index2addr(L, idx); | 294 | const TValue *o = index2value(L, idx); |
| 279 | return tonumber(o, &n); | 295 | return tonumber(o, &n); |
| 280 | } | 296 | } |
| 281 | 297 | ||
| 282 | 298 | ||
| 283 | LUA_API int lua_isstring (lua_State *L, int idx) { | 299 | LUA_API int lua_isstring (lua_State *L, int idx) { |
| 284 | const TValue *o = index2addr(L, idx); | 300 | const TValue *o = index2value(L, idx); |
| 285 | return (ttisstring(o) || cvt2str(o)); | 301 | return (ttisstring(o) || cvt2str(o)); |
| 286 | } | 302 | } |
| 287 | 303 | ||
| 288 | 304 | ||
| 289 | LUA_API int lua_isuserdata (lua_State *L, int idx) { | 305 | LUA_API int lua_isuserdata (lua_State *L, int idx) { |
| 290 | const TValue *o = index2addr(L, idx); | 306 | const TValue *o = index2value(L, idx); |
| 291 | return (ttisfulluserdata(o) || ttislightuserdata(o)); | 307 | return (ttisfulluserdata(o) || ttislightuserdata(o)); |
| 292 | } | 308 | } |
| 293 | 309 | ||
| 294 | 310 | ||
| 295 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | 311 | LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { |
| 296 | StkId o1 = index2addr(L, index1); | 312 | const TValue *o1 = index2value(L, index1); |
| 297 | StkId o2 = index2addr(L, index2); | 313 | const TValue *o2 = index2value(L, index2); |
| 298 | return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0; | 314 | return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0; |
| 299 | } | 315 | } |
| 300 | 316 | ||
| @@ -309,18 +325,19 @@ LUA_API void lua_arith (lua_State *L, int op) { | |||
| 309 | api_incr_top(L); | 325 | api_incr_top(L); |
| 310 | } | 326 | } |
| 311 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ | 327 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ |
| 312 | luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2); | 328 | luaO_arith(L, op, s2v(L->top - 2), s2v(L->top - 1), L->top - 2); |
| 313 | L->top--; /* remove second operand */ | 329 | L->top--; /* remove second operand */ |
| 314 | lua_unlock(L); | 330 | lua_unlock(L); |
| 315 | } | 331 | } |
| 316 | 332 | ||
| 317 | 333 | ||
| 318 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | 334 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { |
| 319 | StkId o1, o2; | 335 | const TValue *o1; |
| 336 | const TValue *o2; | ||
| 320 | int i = 0; | 337 | int i = 0; |
| 321 | lua_lock(L); /* may call tag method */ | 338 | lua_lock(L); /* may call tag method */ |
| 322 | o1 = index2addr(L, index1); | 339 | o1 = index2value(L, index1); |
| 323 | o2 = index2addr(L, index2); | 340 | o2 = index2value(L, index2); |
| 324 | if (isvalid(o1) && isvalid(o2)) { | 341 | if (isvalid(o1) && isvalid(o2)) { |
| 325 | switch (op) { | 342 | switch (op) { |
| 326 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; | 343 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; |
| @@ -335,7 +352,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { | |||
| 335 | 352 | ||
| 336 | 353 | ||
| 337 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { | 354 | LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { |
| 338 | size_t sz = luaO_str2num(s, L->top); | 355 | size_t sz = luaO_str2num(s, s2v(L->top)); |
| 339 | if (sz != 0) | 356 | if (sz != 0) |
| 340 | api_incr_top(L); | 357 | api_incr_top(L); |
| 341 | return sz; | 358 | return sz; |
| @@ -344,7 +361,7 @@ LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { | |||
| 344 | 361 | ||
| 345 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { | 362 | LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { |
| 346 | lua_Number n; | 363 | lua_Number n; |
| 347 | const TValue *o = index2addr(L, idx); | 364 | const TValue *o = index2value(L, idx); |
| 348 | int isnum = tonumber(o, &n); | 365 | int isnum = tonumber(o, &n); |
| 349 | if (!isnum) | 366 | if (!isnum) |
| 350 | n = 0; /* call to 'tonumber' may change 'n' even if it fails */ | 367 | n = 0; /* call to 'tonumber' may change 'n' even if it fails */ |
| @@ -355,7 +372,7 @@ LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { | |||
| 355 | 372 | ||
| 356 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { | 373 | LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { |
| 357 | lua_Integer res; | 374 | lua_Integer res; |
| 358 | const TValue *o = index2addr(L, idx); | 375 | const TValue *o = index2value(L, idx); |
| 359 | int isnum = tointeger(o, &res); | 376 | int isnum = tointeger(o, &res); |
| 360 | if (!isnum) | 377 | if (!isnum) |
| 361 | res = 0; /* call to 'tointeger' may change 'n' even if it fails */ | 378 | res = 0; /* call to 'tointeger' may change 'n' even if it fails */ |
| @@ -365,13 +382,13 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { | |||
| 365 | 382 | ||
| 366 | 383 | ||
| 367 | LUA_API int lua_toboolean (lua_State *L, int idx) { | 384 | LUA_API int lua_toboolean (lua_State *L, int idx) { |
| 368 | const TValue *o = index2addr(L, idx); | 385 | const TValue *o = index2value(L, idx); |
| 369 | return !l_isfalse(o); | 386 | return !l_isfalse(o); |
| 370 | } | 387 | } |
| 371 | 388 | ||
| 372 | 389 | ||
| 373 | LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | 390 | LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { |
| 374 | StkId o = index2addr(L, idx); | 391 | TValue *o = index2value(L, idx); |
| 375 | if (!ttisstring(o)) { | 392 | if (!ttisstring(o)) { |
| 376 | if (!cvt2str(o)) { /* not convertible? */ | 393 | if (!cvt2str(o)) { /* not convertible? */ |
| 377 | if (len != NULL) *len = 0; | 394 | if (len != NULL) *len = 0; |
| @@ -380,7 +397,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
| 380 | lua_lock(L); /* 'luaO_tostring' may create a new string */ | 397 | lua_lock(L); /* 'luaO_tostring' may create a new string */ |
| 381 | luaO_tostring(L, o); | 398 | luaO_tostring(L, o); |
| 382 | luaC_checkGC(L); | 399 | luaC_checkGC(L); |
| 383 | o = index2addr(L, idx); /* previous call may reallocate the stack */ | 400 | o = index2value(L, idx); /* previous call may reallocate the stack */ |
| 384 | lua_unlock(L); | 401 | lua_unlock(L); |
| 385 | } | 402 | } |
| 386 | if (len != NULL) | 403 | if (len != NULL) |
| @@ -390,7 +407,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | |||
| 390 | 407 | ||
| 391 | 408 | ||
| 392 | LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { | 409 | LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { |
| 393 | StkId o = index2addr(L, idx); | 410 | const TValue *o = index2value(L, idx); |
| 394 | switch (ttype(o)) { | 411 | switch (ttype(o)) { |
| 395 | case LUA_TSHRSTR: return tsvalue(o)->shrlen; | 412 | case LUA_TSHRSTR: return tsvalue(o)->shrlen; |
| 396 | case LUA_TLNGSTR: return tsvalue(o)->u.lnglen; | 413 | case LUA_TLNGSTR: return tsvalue(o)->u.lnglen; |
| @@ -402,7 +419,7 @@ LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { | |||
| 402 | 419 | ||
| 403 | 420 | ||
| 404 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | 421 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { |
| 405 | StkId o = index2addr(L, idx); | 422 | const TValue *o = index2value(L, idx); |
| 406 | if (ttislcf(o)) return fvalue(o); | 423 | if (ttislcf(o)) return fvalue(o); |
| 407 | else if (ttisCclosure(o)) | 424 | else if (ttisCclosure(o)) |
| 408 | return clCvalue(o)->f; | 425 | return clCvalue(o)->f; |
| @@ -411,7 +428,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | |||
| 411 | 428 | ||
| 412 | 429 | ||
| 413 | LUA_API void *lua_touserdata (lua_State *L, int idx) { | 430 | LUA_API void *lua_touserdata (lua_State *L, int idx) { |
| 414 | StkId o = index2addr(L, idx); | 431 | const TValue *o = index2value(L, idx); |
| 415 | switch (ttnov(o)) { | 432 | switch (ttnov(o)) { |
| 416 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); | 433 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); |
| 417 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 434 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
| @@ -421,13 +438,13 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { | |||
| 421 | 438 | ||
| 422 | 439 | ||
| 423 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { | 440 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { |
| 424 | StkId o = index2addr(L, idx); | 441 | const TValue *o = index2value(L, idx); |
| 425 | return (!ttisthread(o)) ? NULL : thvalue(o); | 442 | return (!ttisthread(o)) ? NULL : thvalue(o); |
| 426 | } | 443 | } |
| 427 | 444 | ||
| 428 | 445 | ||
| 429 | LUA_API const void *lua_topointer (lua_State *L, int idx) { | 446 | LUA_API const void *lua_topointer (lua_State *L, int idx) { |
| 430 | StkId o = index2addr(L, idx); | 447 | const TValue *o = index2value(L, idx); |
| 431 | switch (ttype(o)) { | 448 | switch (ttype(o)) { |
| 432 | case LUA_TTABLE: return hvalue(o); | 449 | case LUA_TTABLE: return hvalue(o); |
| 433 | case LUA_TLCL: return clLvalue(o); | 450 | case LUA_TLCL: return clLvalue(o); |
| @@ -449,7 +466,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) { | |||
| 449 | 466 | ||
| 450 | LUA_API void lua_pushnil (lua_State *L) { | 467 | LUA_API void lua_pushnil (lua_State *L) { |
| 451 | lua_lock(L); | 468 | lua_lock(L); |
| 452 | setnilvalue(L->top); | 469 | setnilvalue(s2v(L->top)); |
| 453 | api_incr_top(L); | 470 | api_incr_top(L); |
| 454 | lua_unlock(L); | 471 | lua_unlock(L); |
| 455 | } | 472 | } |
| @@ -457,7 +474,7 @@ LUA_API void lua_pushnil (lua_State *L) { | |||
| 457 | 474 | ||
| 458 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 475 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
| 459 | lua_lock(L); | 476 | lua_lock(L); |
| 460 | setfltvalue(L->top, n); | 477 | setfltvalue(s2v(L->top), n); |
| 461 | api_incr_top(L); | 478 | api_incr_top(L); |
| 462 | lua_unlock(L); | 479 | lua_unlock(L); |
| 463 | } | 480 | } |
| @@ -465,7 +482,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
| 465 | 482 | ||
| 466 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | 483 | LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { |
| 467 | lua_lock(L); | 484 | lua_lock(L); |
| 468 | setivalue(L->top, n); | 485 | setivalue(s2v(L->top), n); |
| 469 | api_incr_top(L); | 486 | api_incr_top(L); |
| 470 | lua_unlock(L); | 487 | lua_unlock(L); |
| 471 | } | 488 | } |
| @@ -491,7 +508,7 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | |||
| 491 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { | 508 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { |
| 492 | lua_lock(L); | 509 | lua_lock(L); |
| 493 | if (s == NULL) | 510 | if (s == NULL) |
| 494 | setnilvalue(L->top); | 511 | setnilvalue(s2v(L->top)); |
| 495 | else { | 512 | else { |
| 496 | TString *ts; | 513 | TString *ts; |
| 497 | ts = luaS_new(L, s); | 514 | ts = luaS_new(L, s); |
| @@ -532,7 +549,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { | |||
| 532 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | 549 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { |
| 533 | lua_lock(L); | 550 | lua_lock(L); |
| 534 | if (n == 0) { | 551 | if (n == 0) { |
| 535 | setfvalue(L->top, fn); | 552 | setfvalue(s2v(L->top), fn); |
| 536 | } | 553 | } |
| 537 | else { | 554 | else { |
| 538 | CClosure *cl; | 555 | CClosure *cl; |
| @@ -542,10 +559,10 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
| 542 | cl->f = fn; | 559 | cl->f = fn; |
| 543 | L->top -= n; | 560 | L->top -= n; |
| 544 | while (n--) { | 561 | while (n--) { |
| 545 | setobj2n(L, &cl->upvalue[n], L->top + n); | 562 | setobj2n(L, &cl->upvalue[n], s2v(L->top + n)); |
| 546 | /* does not need barrier because closure is white */ | 563 | /* does not need barrier because closure is white */ |
| 547 | } | 564 | } |
| 548 | setclCvalue(L, L->top, cl); | 565 | setclCvalue(L, s2v(L->top), cl); |
| 549 | } | 566 | } |
| 550 | api_incr_top(L); | 567 | api_incr_top(L); |
| 551 | luaC_checkGC(L); | 568 | luaC_checkGC(L); |
| @@ -555,7 +572,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
| 555 | 572 | ||
| 556 | LUA_API void lua_pushboolean (lua_State *L, int b) { | 573 | LUA_API void lua_pushboolean (lua_State *L, int b) { |
| 557 | lua_lock(L); | 574 | lua_lock(L); |
| 558 | setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ | 575 | setbvalue(s2v(L->top), (b != 0)); /* ensure that true is 1 */ |
| 559 | api_incr_top(L); | 576 | api_incr_top(L); |
| 560 | lua_unlock(L); | 577 | lua_unlock(L); |
| 561 | } | 578 | } |
| @@ -563,7 +580,7 @@ LUA_API void lua_pushboolean (lua_State *L, int b) { | |||
| 563 | 580 | ||
| 564 | LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { | 581 | LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { |
| 565 | lua_lock(L); | 582 | lua_lock(L); |
| 566 | setpvalue(L->top, p); | 583 | setpvalue(s2v(L->top), p); |
| 567 | api_incr_top(L); | 584 | api_incr_top(L); |
| 568 | lua_unlock(L); | 585 | lua_unlock(L); |
| 569 | } | 586 | } |
| @@ -571,7 +588,7 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) { | |||
| 571 | 588 | ||
| 572 | LUA_API int lua_pushthread (lua_State *L) { | 589 | LUA_API int lua_pushthread (lua_State *L) { |
| 573 | lua_lock(L); | 590 | lua_lock(L); |
| 574 | setthvalue(L, L->top, L); | 591 | setthvalue(L, s2v(L->top), L); |
| 575 | api_incr_top(L); | 592 | api_incr_top(L); |
| 576 | lua_unlock(L); | 593 | lua_unlock(L); |
| 577 | return (G(L)->mainthread == L); | 594 | return (G(L)->mainthread == L); |
| @@ -594,10 +611,10 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 594 | else { | 611 | else { |
| 595 | setsvalue2s(L, L->top, str); | 612 | setsvalue2s(L, L->top, str); |
| 596 | api_incr_top(L); | 613 | api_incr_top(L); |
| 597 | luaV_finishget(L, t, L->top - 1, L->top - 1, slot); | 614 | luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); |
| 598 | } | 615 | } |
| 599 | lua_unlock(L); | 616 | lua_unlock(L); |
| 600 | return ttnov(L->top - 1); | 617 | return ttnov(s2v(L->top - 1)); |
| 601 | } | 618 | } |
| 602 | 619 | ||
| 603 | 620 | ||
| @@ -610,30 +627,30 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
| 610 | 627 | ||
| 611 | LUA_API int lua_gettable (lua_State *L, int idx) { | 628 | LUA_API int lua_gettable (lua_State *L, int idx) { |
| 612 | const TValue *slot; | 629 | const TValue *slot; |
| 613 | StkId t; | 630 | TValue *t; |
| 614 | lua_lock(L); | 631 | lua_lock(L); |
| 615 | t = index2addr(L, idx); | 632 | t = index2value(L, idx); |
| 616 | if (luaV_fastget(L, t, L->top - 1, slot, luaH_get)) { | 633 | if (luaV_fastget(L, t, s2v(L->top - 1), slot, luaH_get)) { |
| 617 | setobj2s(L, L->top - 1, slot); | 634 | setobj2s(L, L->top - 1, slot); |
| 618 | } | 635 | } |
| 619 | else | 636 | else |
| 620 | luaV_finishget(L, t, L->top - 1, L->top - 1, slot); | 637 | luaV_finishget(L, t, s2v(L->top - 1), L->top - 1, slot); |
| 621 | lua_unlock(L); | 638 | lua_unlock(L); |
| 622 | return ttnov(L->top - 1); | 639 | return ttnov(s2v(L->top - 1)); |
| 623 | } | 640 | } |
| 624 | 641 | ||
| 625 | 642 | ||
| 626 | LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { | 643 | LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { |
| 627 | lua_lock(L); | 644 | lua_lock(L); |
| 628 | return auxgetstr(L, index2addr(L, idx), k); | 645 | return auxgetstr(L, index2value(L, idx), k); |
| 629 | } | 646 | } |
| 630 | 647 | ||
| 631 | 648 | ||
| 632 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | 649 | LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { |
| 633 | StkId t; | 650 | TValue *t; |
| 634 | const TValue *slot; | 651 | const TValue *slot; |
| 635 | lua_lock(L); | 652 | lua_lock(L); |
| 636 | t = index2addr(L, idx); | 653 | t = index2value(L, idx); |
| 637 | if (luaV_fastgeti(L, t, n, slot)) { | 654 | if (luaV_fastgeti(L, t, n, slot)) { |
| 638 | setobj2s(L, L->top, slot); | 655 | setobj2s(L, L->top, slot); |
| 639 | } | 656 | } |
| @@ -644,44 +661,44 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
| 644 | } | 661 | } |
| 645 | api_incr_top(L); | 662 | api_incr_top(L); |
| 646 | lua_unlock(L); | 663 | lua_unlock(L); |
| 647 | return ttnov(L->top - 1); | 664 | return ttnov(s2v(L->top - 1)); |
| 648 | } | 665 | } |
| 649 | 666 | ||
| 650 | 667 | ||
| 651 | LUA_API int lua_rawget (lua_State *L, int idx) { | 668 | LUA_API int lua_rawget (lua_State *L, int idx) { |
| 652 | StkId t; | 669 | TValue *t; |
| 653 | lua_lock(L); | 670 | lua_lock(L); |
| 654 | t = index2addr(L, idx); | 671 | t = index2value(L, idx); |
| 655 | api_check(L, ttistable(t), "table expected"); | 672 | api_check(L, ttistable(t), "table expected"); |
| 656 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 673 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), s2v(L->top - 1))); |
| 657 | lua_unlock(L); | 674 | lua_unlock(L); |
| 658 | return ttnov(L->top - 1); | 675 | return ttnov(s2v(L->top - 1)); |
| 659 | } | 676 | } |
| 660 | 677 | ||
| 661 | 678 | ||
| 662 | LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { | 679 | LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { |
| 663 | StkId t; | 680 | TValue *t; |
| 664 | lua_lock(L); | 681 | lua_lock(L); |
| 665 | t = index2addr(L, idx); | 682 | t = index2value(L, idx); |
| 666 | api_check(L, ttistable(t), "table expected"); | 683 | api_check(L, ttistable(t), "table expected"); |
| 667 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); | 684 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); |
| 668 | api_incr_top(L); | 685 | api_incr_top(L); |
| 669 | lua_unlock(L); | 686 | lua_unlock(L); |
| 670 | return ttnov(L->top - 1); | 687 | return ttnov(s2v(L->top - 1)); |
| 671 | } | 688 | } |
| 672 | 689 | ||
| 673 | 690 | ||
| 674 | LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { | 691 | LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { |
| 675 | StkId t; | 692 | TValue *t; |
| 676 | TValue k; | 693 | TValue k; |
| 677 | lua_lock(L); | 694 | lua_lock(L); |
| 678 | t = index2addr(L, idx); | 695 | t = index2value(L, idx); |
| 679 | api_check(L, ttistable(t), "table expected"); | 696 | api_check(L, ttistable(t), "table expected"); |
| 680 | setpvalue(&k, cast(void *, p)); | 697 | setpvalue(&k, cast(void *, p)); |
| 681 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); | 698 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); |
| 682 | api_incr_top(L); | 699 | api_incr_top(L); |
| 683 | lua_unlock(L); | 700 | lua_unlock(L); |
| 684 | return ttnov(L->top - 1); | 701 | return ttnov(s2v(L->top - 1)); |
| 685 | } | 702 | } |
| 686 | 703 | ||
| 687 | 704 | ||
| @@ -689,7 +706,7 @@ LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { | |||
| 689 | Table *t; | 706 | Table *t; |
| 690 | lua_lock(L); | 707 | lua_lock(L); |
| 691 | t = luaH_new(L); | 708 | t = luaH_new(L); |
| 692 | sethvalue(L, L->top, t); | 709 | sethvalue2s(L, L->top, t); |
| 693 | api_incr_top(L); | 710 | api_incr_top(L); |
| 694 | if (narray > 0 || nrec > 0) | 711 | if (narray > 0 || nrec > 0) |
| 695 | luaH_resize(L, t, narray, nrec); | 712 | luaH_resize(L, t, narray, nrec); |
| @@ -703,7 +720,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
| 703 | Table *mt; | 720 | Table *mt; |
| 704 | int res = 0; | 721 | int res = 0; |
| 705 | lua_lock(L); | 722 | lua_lock(L); |
| 706 | obj = index2addr(L, objindex); | 723 | obj = index2value(L, objindex); |
| 707 | switch (ttnov(obj)) { | 724 | switch (ttnov(obj)) { |
| 708 | case LUA_TTABLE: | 725 | case LUA_TTABLE: |
| 709 | mt = hvalue(obj)->metatable; | 726 | mt = hvalue(obj)->metatable; |
| @@ -716,7 +733,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
| 716 | break; | 733 | break; |
| 717 | } | 734 | } |
| 718 | if (mt != NULL) { | 735 | if (mt != NULL) { |
| 719 | sethvalue(L, L->top, mt); | 736 | sethvalue2s(L, L->top, mt); |
| 720 | api_incr_top(L); | 737 | api_incr_top(L); |
| 721 | res = 1; | 738 | res = 1; |
| 722 | } | 739 | } |
| @@ -726,14 +743,14 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { | |||
| 726 | 743 | ||
| 727 | 744 | ||
| 728 | LUA_API int lua_getuservalue (lua_State *L, int idx) { | 745 | LUA_API int lua_getuservalue (lua_State *L, int idx) { |
| 729 | StkId o; | 746 | TValue *o; |
| 730 | lua_lock(L); | 747 | lua_lock(L); |
| 731 | o = index2addr(L, idx); | 748 | o = index2value(L, idx); |
| 732 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 749 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
| 733 | getuservalue(L, uvalue(o), L->top); | 750 | getuservalue(L, uvalue(o), s2v(L->top)); |
| 734 | api_incr_top(L); | 751 | api_incr_top(L); |
| 735 | lua_unlock(L); | 752 | lua_unlock(L); |
| 736 | return ttnov(L->top - 1); | 753 | return ttnov(s2v(L->top - 1)); |
| 737 | } | 754 | } |
| 738 | 755 | ||
| 739 | 756 | ||
| @@ -749,13 +766,13 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 749 | TString *str = luaS_new(L, k); | 766 | TString *str = luaS_new(L, k); |
| 750 | api_checknelems(L, 1); | 767 | api_checknelems(L, 1); |
| 751 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { | 768 | if (luaV_fastget(L, t, str, slot, luaH_getstr)) { |
| 752 | luaV_finishfastset(L, t, slot, L->top - 1); | 769 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); |
| 753 | L->top--; /* pop value */ | 770 | L->top--; /* pop value */ |
| 754 | } | 771 | } |
| 755 | else { | 772 | else { |
| 756 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ | 773 | setsvalue2s(L, L->top, str); /* push 'str' (to make it a TValue) */ |
| 757 | api_incr_top(L); | 774 | api_incr_top(L); |
| 758 | luaV_finishset(L, t, L->top - 1, L->top - 2, slot); | 775 | luaV_finishset(L, t, s2v(L->top - 1), s2v(L->top - 2), slot); |
| 759 | L->top -= 2; /* pop value and key */ | 776 | L->top -= 2; /* pop value and key */ |
| 760 | } | 777 | } |
| 761 | lua_unlock(L); /* lock done by caller */ | 778 | lua_unlock(L); /* lock done by caller */ |
| @@ -770,16 +787,16 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) { | |||
| 770 | 787 | ||
| 771 | 788 | ||
| 772 | LUA_API void lua_settable (lua_State *L, int idx) { | 789 | LUA_API void lua_settable (lua_State *L, int idx) { |
| 773 | StkId t; | 790 | TValue *t; |
| 774 | const TValue *slot; | 791 | const TValue *slot; |
| 775 | lua_lock(L); | 792 | lua_lock(L); |
| 776 | api_checknelems(L, 2); | 793 | api_checknelems(L, 2); |
| 777 | t = index2addr(L, idx); | 794 | t = index2value(L, idx); |
| 778 | if (luaV_fastget(L, t, L->top - 2, slot, luaH_get)) { | 795 | if (luaV_fastget(L, t, s2v(L->top - 2), slot, luaH_get)) { |
| 779 | luaV_finishfastset(L, t, slot, L->top - 1); | 796 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); |
| 780 | } | 797 | } |
| 781 | else | 798 | else |
| 782 | luaV_finishset(L, t, L->top - 2, L->top - 1, slot); | 799 | luaV_finishset(L, t, s2v(L->top - 2), s2v(L->top - 1), slot); |
| 783 | L->top -= 2; /* pop index and value */ | 800 | L->top -= 2; /* pop index and value */ |
| 784 | lua_unlock(L); | 801 | lua_unlock(L); |
| 785 | } | 802 | } |
| @@ -787,23 +804,23 @@ LUA_API void lua_settable (lua_State *L, int idx) { | |||
| 787 | 804 | ||
| 788 | LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { | 805 | LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { |
| 789 | lua_lock(L); /* unlock done in 'auxsetstr' */ | 806 | lua_lock(L); /* unlock done in 'auxsetstr' */ |
| 790 | auxsetstr(L, index2addr(L, idx), k); | 807 | auxsetstr(L, index2value(L, idx), k); |
| 791 | } | 808 | } |
| 792 | 809 | ||
| 793 | 810 | ||
| 794 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | 811 | LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { |
| 795 | StkId t; | 812 | TValue *t; |
| 796 | const TValue *slot; | 813 | const TValue *slot; |
| 797 | lua_lock(L); | 814 | lua_lock(L); |
| 798 | api_checknelems(L, 1); | 815 | api_checknelems(L, 1); |
| 799 | t = index2addr(L, idx); | 816 | t = index2value(L, idx); |
| 800 | if (luaV_fastgeti(L, t, n, slot)) { | 817 | if (luaV_fastgeti(L, t, n, slot)) { |
| 801 | luaV_finishfastset(L, t, slot, L->top - 1); | 818 | luaV_finishfastset(L, t, slot, s2v(L->top - 1)); |
| 802 | } | 819 | } |
| 803 | else { | 820 | else { |
| 804 | TValue aux; | 821 | TValue aux; |
| 805 | setivalue(&aux, n); | 822 | setivalue(&aux, n); |
| 806 | luaV_finishset(L, t, &aux, L->top - 1, slot); | 823 | luaV_finishset(L, t, &aux, s2v(L->top - 1), slot); |
| 807 | } | 824 | } |
| 808 | L->top--; /* pop value */ | 825 | L->top--; /* pop value */ |
| 809 | lua_unlock(L); | 826 | lua_unlock(L); |
| @@ -811,45 +828,45 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | |||
| 811 | 828 | ||
| 812 | 829 | ||
| 813 | LUA_API void lua_rawset (lua_State *L, int idx) { | 830 | LUA_API void lua_rawset (lua_State *L, int idx) { |
| 814 | StkId o; | 831 | TValue *o; |
| 815 | TValue *slot; | 832 | TValue *slot; |
| 816 | lua_lock(L); | 833 | lua_lock(L); |
| 817 | api_checknelems(L, 2); | 834 | api_checknelems(L, 2); |
| 818 | o = index2addr(L, idx); | 835 | o = index2value(L, idx); |
| 819 | api_check(L, ttistable(o), "table expected"); | 836 | api_check(L, ttistable(o), "table expected"); |
| 820 | slot = luaH_set(L, hvalue(o), L->top - 2); | 837 | slot = luaH_set(L, hvalue(o), s2v(L->top - 2)); |
| 821 | setobj2t(L, slot, L->top - 1); | 838 | setobj2t(L, slot, s2v(L->top - 1)); |
| 822 | invalidateTMcache(hvalue(o)); | 839 | invalidateTMcache(hvalue(o)); |
| 823 | luaC_barrierback(L, hvalue(o), L->top-1); | 840 | luaC_barrierback(L, hvalue(o), s2v(L->top - 1)); |
| 824 | L->top -= 2; | 841 | L->top -= 2; |
| 825 | lua_unlock(L); | 842 | lua_unlock(L); |
| 826 | } | 843 | } |
| 827 | 844 | ||
| 828 | 845 | ||
| 829 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { | 846 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { |
| 830 | StkId o; | 847 | TValue *o; |
| 831 | lua_lock(L); | 848 | lua_lock(L); |
| 832 | api_checknelems(L, 1); | 849 | api_checknelems(L, 1); |
| 833 | o = index2addr(L, idx); | 850 | o = index2value(L, idx); |
| 834 | api_check(L, ttistable(o), "table expected"); | 851 | api_check(L, ttistable(o), "table expected"); |
| 835 | luaH_setint(L, hvalue(o), n, L->top - 1); | 852 | luaH_setint(L, hvalue(o), n, s2v(L->top - 1)); |
| 836 | luaC_barrierback(L, hvalue(o), L->top-1); | 853 | luaC_barrierback(L, hvalue(o), s2v(L->top - 1)); |
| 837 | L->top--; | 854 | L->top--; |
| 838 | lua_unlock(L); | 855 | lua_unlock(L); |
| 839 | } | 856 | } |
| 840 | 857 | ||
| 841 | 858 | ||
| 842 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { | 859 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { |
| 843 | StkId o; | 860 | TValue *o; |
| 844 | TValue k, *slot; | 861 | TValue k, *slot; |
| 845 | lua_lock(L); | 862 | lua_lock(L); |
| 846 | api_checknelems(L, 1); | 863 | api_checknelems(L, 1); |
| 847 | o = index2addr(L, idx); | 864 | o = index2value(L, idx); |
| 848 | api_check(L, ttistable(o), "table expected"); | 865 | api_check(L, ttistable(o), "table expected"); |
| 849 | setpvalue(&k, cast(void *, p)); | 866 | setpvalue(&k, cast(void *, p)); |
| 850 | slot = luaH_set(L, hvalue(o), &k); | 867 | slot = luaH_set(L, hvalue(o), &k); |
| 851 | setobj2t(L, slot, L->top - 1); | 868 | setobj2t(L, slot, s2v(L->top - 1)); |
| 852 | luaC_barrierback(L, hvalue(o), L->top - 1); | 869 | luaC_barrierback(L, hvalue(o), s2v(L->top - 1)); |
| 853 | L->top--; | 870 | L->top--; |
| 854 | lua_unlock(L); | 871 | lua_unlock(L); |
| 855 | } | 872 | } |
| @@ -860,12 +877,12 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
| 860 | Table *mt; | 877 | Table *mt; |
| 861 | lua_lock(L); | 878 | lua_lock(L); |
| 862 | api_checknelems(L, 1); | 879 | api_checknelems(L, 1); |
| 863 | obj = index2addr(L, objindex); | 880 | obj = index2value(L, objindex); |
| 864 | if (ttisnil(L->top - 1)) | 881 | if (ttisnil(s2v(L->top - 1))) |
| 865 | mt = NULL; | 882 | mt = NULL; |
| 866 | else { | 883 | else { |
| 867 | api_check(L, ttistable(L->top - 1), "table expected"); | 884 | api_check(L, ttistable(s2v(L->top - 1)), "table expected"); |
| 868 | mt = hvalue(L->top - 1); | 885 | mt = hvalue(s2v(L->top - 1)); |
| 869 | } | 886 | } |
| 870 | switch (ttnov(obj)) { | 887 | switch (ttnov(obj)) { |
| 871 | case LUA_TTABLE: { | 888 | case LUA_TTABLE: { |
| @@ -896,13 +913,13 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
| 896 | 913 | ||
| 897 | 914 | ||
| 898 | LUA_API void lua_setuservalue (lua_State *L, int idx) { | 915 | LUA_API void lua_setuservalue (lua_State *L, int idx) { |
| 899 | StkId o; | 916 | TValue *o; |
| 900 | lua_lock(L); | 917 | lua_lock(L); |
| 901 | api_checknelems(L, 1); | 918 | api_checknelems(L, 1); |
| 902 | o = index2addr(L, idx); | 919 | o = index2value(L, idx); |
| 903 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 920 | api_check(L, ttisfulluserdata(o), "full userdata expected"); |
| 904 | setuservalue(L, uvalue(o), L->top - 1); | 921 | setuservalue(L, uvalue(o), s2v(L->top - 1)); |
| 905 | luaC_barrier(L, gcvalue(o), L->top - 1); | 922 | luaC_barrier(L, gcvalue(o), s2v(L->top - 1)); |
| 906 | L->top--; | 923 | L->top--; |
| 907 | lua_unlock(L); | 924 | lua_unlock(L); |
| 908 | } | 925 | } |
| @@ -971,8 +988,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | |||
| 971 | if (errfunc == 0) | 988 | if (errfunc == 0) |
| 972 | func = 0; | 989 | func = 0; |
| 973 | else { | 990 | else { |
| 974 | StkId o = index2addr(L, errfunc); | 991 | StkId o = index2stack(L, errfunc); |
| 975 | api_checkstackindex(L, errfunc, o); | ||
| 976 | func = savestack(L, o); | 992 | func = savestack(L, o); |
| 977 | } | 993 | } |
| 978 | c.func = L->top - (nargs+1); /* function to be called */ | 994 | c.func = L->top - (nargs+1); /* function to be called */ |
| @@ -1010,7 +1026,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
| 1010 | luaZ_init(L, &z, reader, data); | 1026 | luaZ_init(L, &z, reader, data); |
| 1011 | status = luaD_protectedparser(L, &z, chunkname, mode); | 1027 | status = luaD_protectedparser(L, &z, chunkname, mode); |
| 1012 | if (status == LUA_OK) { /* no errors? */ | 1028 | if (status == LUA_OK) { /* no errors? */ |
| 1013 | LClosure *f = clLvalue(L->top - 1); /* get newly created function */ | 1029 | LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ |
| 1014 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ | 1030 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 1015 | /* get global table from registry */ | 1031 | /* get global table from registry */ |
| 1016 | Table *reg = hvalue(&G(L)->l_registry); | 1032 | Table *reg = hvalue(&G(L)->l_registry); |
| @@ -1030,7 +1046,7 @@ LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) { | |||
| 1030 | TValue *o; | 1046 | TValue *o; |
| 1031 | lua_lock(L); | 1047 | lua_lock(L); |
| 1032 | api_checknelems(L, 1); | 1048 | api_checknelems(L, 1); |
| 1033 | o = L->top - 1; | 1049 | o = s2v(L->top - 1); |
| 1034 | if (isLfunction(o)) | 1050 | if (isLfunction(o)) |
| 1035 | status = luaU_dump(L, getproto(o), writer, data, strip); | 1051 | status = luaU_dump(L, getproto(o), writer, data, strip); |
| 1036 | else | 1052 | else |
| @@ -1154,10 +1170,10 @@ LUA_API int lua_error (lua_State *L) { | |||
| 1154 | 1170 | ||
| 1155 | 1171 | ||
| 1156 | LUA_API int lua_next (lua_State *L, int idx) { | 1172 | LUA_API int lua_next (lua_State *L, int idx) { |
| 1157 | StkId t; | 1173 | TValue *t; |
| 1158 | int more; | 1174 | int more; |
| 1159 | lua_lock(L); | 1175 | lua_lock(L); |
| 1160 | t = index2addr(L, idx); | 1176 | t = index2value(L, idx); |
| 1161 | api_check(L, ttistable(t), "table expected"); | 1177 | api_check(L, ttistable(t), "table expected"); |
| 1162 | more = luaH_next(L, hvalue(t), L->top - 1); | 1178 | more = luaH_next(L, hvalue(t), L->top - 1); |
| 1163 | if (more) { | 1179 | if (more) { |
| @@ -1187,9 +1203,9 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
| 1187 | 1203 | ||
| 1188 | 1204 | ||
| 1189 | LUA_API void lua_len (lua_State *L, int idx) { | 1205 | LUA_API void lua_len (lua_State *L, int idx) { |
| 1190 | StkId t; | 1206 | TValue *t; |
| 1191 | lua_lock(L); | 1207 | lua_lock(L); |
| 1192 | t = index2addr(L, idx); | 1208 | t = index2value(L, idx); |
| 1193 | luaV_objlen(L, L->top, t); | 1209 | luaV_objlen(L, L->top, t); |
| 1194 | api_incr_top(L); | 1210 | api_incr_top(L); |
| 1195 | lua_unlock(L); | 1211 | lua_unlock(L); |
| @@ -1218,7 +1234,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
| 1218 | Udata *u; | 1234 | Udata *u; |
| 1219 | lua_lock(L); | 1235 | lua_lock(L); |
| 1220 | u = luaS_newudata(L, size); | 1236 | u = luaS_newudata(L, size); |
| 1221 | setuvalue(L, L->top, u); | 1237 | setuvalue(L, s2v(L->top), u); |
| 1222 | api_incr_top(L); | 1238 | api_incr_top(L); |
| 1223 | luaC_checkGC(L); | 1239 | luaC_checkGC(L); |
| 1224 | lua_unlock(L); | 1240 | lua_unlock(L); |
| @@ -1227,7 +1243,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | |||
| 1227 | 1243 | ||
| 1228 | 1244 | ||
| 1229 | 1245 | ||
| 1230 | static const char *aux_upvalue (StkId fi, int n, TValue **val, | 1246 | static const char *aux_upvalue (TValue *fi, int n, TValue **val, |
| 1231 | GCObject **owner) { | 1247 | GCObject **owner) { |
| 1232 | switch (ttype(fi)) { | 1248 | switch (ttype(fi)) { |
| 1233 | case LUA_TCCL: { /* C closure */ | 1249 | case LUA_TCCL: { /* C closure */ |
| @@ -1256,7 +1272,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { | |||
| 1256 | const char *name; | 1272 | const char *name; |
| 1257 | TValue *val = NULL; /* to avoid warnings */ | 1273 | TValue *val = NULL; /* to avoid warnings */ |
| 1258 | lua_lock(L); | 1274 | lua_lock(L); |
| 1259 | name = aux_upvalue(index2addr(L, funcindex), n, &val, NULL); | 1275 | name = aux_upvalue(index2value(L, funcindex), n, &val, NULL); |
| 1260 | if (name) { | 1276 | if (name) { |
| 1261 | setobj2s(L, L->top, val); | 1277 | setobj2s(L, L->top, val); |
| 1262 | api_incr_top(L); | 1278 | api_incr_top(L); |
| @@ -1270,14 +1286,14 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
| 1270 | const char *name; | 1286 | const char *name; |
| 1271 | TValue *val = NULL; /* to avoid warnings */ | 1287 | TValue *val = NULL; /* to avoid warnings */ |
| 1272 | GCObject *owner = NULL; /* to avoid warnings */ | 1288 | GCObject *owner = NULL; /* to avoid warnings */ |
| 1273 | StkId fi; | 1289 | TValue *fi; |
| 1274 | lua_lock(L); | 1290 | lua_lock(L); |
| 1275 | fi = index2addr(L, funcindex); | 1291 | fi = index2value(L, funcindex); |
| 1276 | api_checknelems(L, 1); | 1292 | api_checknelems(L, 1); |
| 1277 | name = aux_upvalue(fi, n, &val, &owner); | 1293 | name = aux_upvalue(fi, n, &val, &owner); |
| 1278 | if (name) { | 1294 | if (name) { |
| 1279 | L->top--; | 1295 | L->top--; |
| 1280 | setobj(L, val, L->top); | 1296 | setobj(L, val, s2v(L->top)); |
| 1281 | luaC_barrier(L, owner, val); | 1297 | luaC_barrier(L, owner, val); |
| 1282 | } | 1298 | } |
| 1283 | lua_unlock(L); | 1299 | lua_unlock(L); |
| @@ -1287,7 +1303,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | |||
| 1287 | 1303 | ||
| 1288 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { | 1304 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { |
| 1289 | LClosure *f; | 1305 | LClosure *f; |
| 1290 | StkId fi = index2addr(L, fidx); | 1306 | TValue *fi = index2value(L, fidx); |
| 1291 | api_check(L, ttisLclosure(fi), "Lua function expected"); | 1307 | api_check(L, ttisLclosure(fi), "Lua function expected"); |
| 1292 | f = clLvalue(fi); | 1308 | f = clLvalue(fi); |
| 1293 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); | 1309 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); |
| @@ -1297,7 +1313,7 @@ static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { | |||
| 1297 | 1313 | ||
| 1298 | 1314 | ||
| 1299 | LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { | 1315 | LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { |
| 1300 | StkId fi = index2addr(L, fidx); | 1316 | TValue *fi = index2value(L, fidx); |
| 1301 | switch (ttype(fi)) { | 1317 | switch (ttype(fi)) { |
| 1302 | case LUA_TLCL: { /* lua closure */ | 1318 | case LUA_TLCL: { /* lua closure */ |
| 1303 | return *getupvalref(L, fidx, n, NULL); | 1319 | return *getupvalref(L, fidx, n, NULL); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.119 2017/05/18 19:44:19 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.120 2017/06/27 11:35:31 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 | */ |
| @@ -1079,7 +1079,7 @@ static int constfolding (FuncState *fs, int op, expdesc *e1, | |||
| 1079 | TValue v1, v2, res; | 1079 | TValue v1, v2, res; |
| 1080 | if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) | 1080 | if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2)) |
| 1081 | return 0; /* non-numeric operands or not safe to fold */ | 1081 | return 0; /* non-numeric operands or not safe to fold */ |
| 1082 | luaO_arith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ | 1082 | luaO_rawarith(fs->ls->L, op, &v1, &v2, &res); /* does operation */ |
| 1083 | if (ttisinteger(&res)) { | 1083 | if (ttisinteger(&res)) { |
| 1084 | e1->k = VKINT; | 1084 | e1->k = VKINT; |
| 1085 | e1->u.ival = ivalue(&res); | 1085 | e1->u.ival = ivalue(&res); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.126 2017/05/13 13:54:47 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.127 2017/06/27 11:35:31 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 | */ |
| @@ -35,7 +35,7 @@ | |||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | /* Active Lua function (given call info) */ | 37 | /* Active Lua function (given call info) */ |
| 38 | #define ci_func(ci) (clLvalue((ci)->func)) | 38 | #define ci_func(ci) (clLvalue(s2v((ci)->func))) |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | static const char *funcnamefromcode (lua_State *L, CallInfo *ci, | 41 | static const char *funcnamefromcode (lua_State *L, CallInfo *ci, |
| @@ -211,16 +211,16 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
| 211 | lua_lock(L); | 211 | lua_lock(L); |
| 212 | swapextra(L); | 212 | swapextra(L); |
| 213 | if (ar == NULL) { /* information about non-active function? */ | 213 | if (ar == NULL) { /* information about non-active function? */ |
| 214 | if (!isLfunction(L->top - 1)) /* not a Lua function? */ | 214 | if (!isLfunction(s2v(L->top - 1))) /* not a Lua function? */ |
| 215 | name = NULL; | 215 | name = NULL; |
| 216 | else /* consider live variables at function start (parameters) */ | 216 | else /* consider live variables at function start (parameters) */ |
| 217 | name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0); | 217 | name = luaF_getlocalname(clLvalue(s2v(L->top - 1))->p, n, 0); |
| 218 | } | 218 | } |
| 219 | else { /* active function; get information through 'ar' */ | 219 | else { /* active function; get information through 'ar' */ |
| 220 | StkId pos = NULL; /* to avoid warnings */ | 220 | StkId pos = NULL; /* to avoid warnings */ |
| 221 | name = findlocal(L, ar->i_ci, n, &pos); | 221 | name = findlocal(L, ar->i_ci, n, &pos); |
| 222 | if (name) { | 222 | if (name) { |
| 223 | setobj2s(L, L->top, pos); | 223 | setobjs2s(L, L->top, pos); |
| 224 | api_incr_top(L); | 224 | api_incr_top(L); |
| 225 | } | 225 | } |
| 226 | } | 226 | } |
| @@ -274,7 +274,7 @@ static int nextline (Proto *p, int currentline, int pc) { | |||
| 274 | 274 | ||
| 275 | static void collectvalidlines (lua_State *L, Closure *f) { | 275 | static void collectvalidlines (lua_State *L, Closure *f) { |
| 276 | if (noLuaClosure(f)) { | 276 | if (noLuaClosure(f)) { |
| 277 | setnilvalue(L->top); | 277 | setnilvalue(s2v(L->top)); |
| 278 | api_incr_top(L); | 278 | api_incr_top(L); |
| 279 | } | 279 | } |
| 280 | else { | 280 | else { |
| @@ -283,7 +283,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { | |||
| 283 | Proto *p = f->l.p; | 283 | Proto *p = f->l.p; |
| 284 | int currentline = p->linedefined; | 284 | int currentline = p->linedefined; |
| 285 | Table *t = luaH_new(L); /* new table to store active lines */ | 285 | Table *t = luaH_new(L); /* new table to store active lines */ |
| 286 | sethvalue(L, L->top, t); /* push it on stack */ | 286 | sethvalue2s(L, L->top, t); /* push it on stack */ |
| 287 | api_incr_top(L); | 287 | api_incr_top(L); |
| 288 | setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */ | 288 | setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */ |
| 289 | for (i = 0; i < p->sizelineinfo; i++) { /* for all lines with code */ | 289 | for (i = 0; i < p->sizelineinfo; i++) { /* for all lines with code */ |
| @@ -359,25 +359,25 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
| 359 | int status; | 359 | int status; |
| 360 | Closure *cl; | 360 | Closure *cl; |
| 361 | CallInfo *ci; | 361 | CallInfo *ci; |
| 362 | StkId func; | 362 | TValue *func; |
| 363 | lua_lock(L); | 363 | lua_lock(L); |
| 364 | swapextra(L); | 364 | swapextra(L); |
| 365 | if (*what == '>') { | 365 | if (*what == '>') { |
| 366 | ci = NULL; | 366 | ci = NULL; |
| 367 | func = L->top - 1; | 367 | func = s2v(L->top - 1); |
| 368 | api_check(L, ttisfunction(func), "function expected"); | 368 | api_check(L, ttisfunction(func), "function expected"); |
| 369 | what++; /* skip the '>' */ | 369 | what++; /* skip the '>' */ |
| 370 | L->top--; /* pop function */ | 370 | L->top--; /* pop function */ |
| 371 | } | 371 | } |
| 372 | else { | 372 | else { |
| 373 | ci = ar->i_ci; | 373 | ci = ar->i_ci; |
| 374 | func = ci->func; | 374 | func = s2v(ci->func); |
| 375 | lua_assert(ttisfunction(ci->func)); | 375 | lua_assert(ttisfunction(func)); |
| 376 | } | 376 | } |
| 377 | cl = ttisclosure(func) ? clvalue(func) : NULL; | 377 | cl = ttisclosure(func) ? clvalue(func) : NULL; |
| 378 | status = auxgetinfo(L, what, ar, cl, ci); | 378 | status = auxgetinfo(L, what, ar, cl, ci); |
| 379 | if (strchr(what, 'f')) { | 379 | if (strchr(what, 'f')) { |
| 380 | setobjs2s(L, L->top, func); | 380 | setobj2s(L, L->top, func); |
| 381 | api_incr_top(L); | 381 | api_incr_top(L); |
| 382 | } | 382 | } |
| 383 | swapextra(L); /* correct before option 'L', which can raise a mem. error */ | 383 | swapextra(L); /* correct before option 'L', which can raise a mem. error */ |
| @@ -627,8 +627,8 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci, | |||
| 627 | */ | 627 | */ |
| 628 | static int isinstack (CallInfo *ci, const TValue *o) { | 628 | static int isinstack (CallInfo *ci, const TValue *o) { |
| 629 | StkId base = ci->func + 1; | 629 | StkId base = ci->func + 1; |
| 630 | ptrdiff_t i = o - base; | 630 | ptrdiff_t i = cast(StkId, o) - base; |
| 631 | return (0 <= i && i < (ci->top - base) && base + i == o); | 631 | return (0 <= i && i < (ci->top - base) && s2v(base + i) == o); |
| 632 | } | 632 | } |
| 633 | 633 | ||
| 634 | 634 | ||
| @@ -659,7 +659,7 @@ static const char *varinfo (lua_State *L, const TValue *o) { | |||
| 659 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ | 659 | kind = getupvalname(ci, o, &name); /* check whether 'o' is an upvalue */ |
| 660 | if (!kind && isinstack(ci, o)) /* no? try a register */ | 660 | if (!kind && isinstack(ci, o)) /* no? try a register */ |
| 661 | kind = getobjname(ci_func(ci)->p, currentpc(ci), | 661 | kind = getobjname(ci_func(ci)->p, currentpc(ci), |
| 662 | cast_int(o - (ci->func + 1)), &name); | 662 | cast_int(cast(StkId, o) - (ci->func + 1)), &name); |
| 663 | } | 663 | } |
| 664 | return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : ""; | 664 | return (kind) ? luaO_pushfstring(L, " (%s '%s')", kind, name) : ""; |
| 665 | } | 665 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.159 2017/05/13 13:54:47 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.160 2017/05/23 12:50: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 | */ |
| @@ -116,7 +116,7 @@ l_noret luaD_throw (lua_State *L, int errcode) { | |||
| 116 | global_State *g = G(L); | 116 | global_State *g = G(L); |
| 117 | L->status = cast_byte(errcode); /* mark it as dead */ | 117 | L->status = cast_byte(errcode); /* mark it as dead */ |
| 118 | if (g->mainthread->errorJmp) { /* main thread has a handler? */ | 118 | if (g->mainthread->errorJmp) { /* main thread has a handler? */ |
| 119 | setobj2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ | 119 | setobjs2s(L, g->mainthread->top++, L->top - 1); /* copy error obj. */ |
| 120 | luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ | 120 | luaD_throw(g->mainthread, errcode); /* re-throw in main thread */ |
| 121 | } | 121 | } |
| 122 | else { /* no handler at all; abort */ | 122 | else { /* no handler at all; abort */ |
| @@ -155,12 +155,12 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { | |||
| 155 | ** Stack reallocation | 155 | ** Stack reallocation |
| 156 | ** =================================================================== | 156 | ** =================================================================== |
| 157 | */ | 157 | */ |
| 158 | static void correctstack (lua_State *L, TValue *oldstack) { | 158 | static void correctstack (lua_State *L, StkId oldstack) { |
| 159 | CallInfo *ci; | 159 | CallInfo *ci; |
| 160 | UpVal *up; | 160 | UpVal *up; |
| 161 | L->top = (L->top - oldstack) + L->stack; | 161 | L->top = (L->top - oldstack) + L->stack; |
| 162 | for (up = L->openupval; up != NULL; up = up->u.open.next) | 162 | for (up = L->openupval; up != NULL; up = up->u.open.next) |
| 163 | up->v = (up->v - oldstack) + L->stack; | 163 | up->v = s2v((uplevel(up) - oldstack) + L->stack); |
| 164 | for (ci = L->ci; ci != NULL; ci = ci->previous) { | 164 | for (ci = L->ci; ci != NULL; ci = ci->previous) { |
| 165 | ci->top = (ci->top - oldstack) + L->stack; | 165 | ci->top = (ci->top - oldstack) + L->stack; |
| 166 | ci->func = (ci->func - oldstack) + L->stack; | 166 | ci->func = (ci->func - oldstack) + L->stack; |
| @@ -173,13 +173,13 @@ static void correctstack (lua_State *L, TValue *oldstack) { | |||
| 173 | 173 | ||
| 174 | 174 | ||
| 175 | void luaD_reallocstack (lua_State *L, int newsize) { | 175 | void luaD_reallocstack (lua_State *L, int newsize) { |
| 176 | TValue *oldstack = L->stack; | 176 | StkId oldstack = L->stack; |
| 177 | int lim = L->stacksize; | 177 | int lim = L->stacksize; |
| 178 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); | 178 | lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); |
| 179 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); | 179 | lua_assert(L->stack_last - L->stack == L->stacksize - EXTRA_STACK); |
| 180 | luaM_reallocvector(L, L->stack, L->stacksize, newsize, TValue); | 180 | luaM_reallocvector(L, L->stack, L->stacksize, newsize, StackValue); |
| 181 | for (; lim < newsize; lim++) | 181 | for (; lim < newsize; lim++) |
| 182 | setnilvalue(L->stack + lim); /* erase new segment */ | 182 | setnilvalue(s2v(L->stack + lim)); /* erase new segment */ |
| 183 | L->stacksize = newsize; | 183 | L->stacksize = newsize; |
| 184 | L->stack_last = L->stack + newsize - EXTRA_STACK; | 184 | L->stack_last = L->stack + newsize - EXTRA_STACK; |
| 185 | correctstack(L, oldstack); | 185 | correctstack(L, oldstack); |
| @@ -294,10 +294,10 @@ static void callhook (lua_State *L, CallInfo *ci) { | |||
| 294 | ** it. Raise an error if __call metafield is not a function. | 294 | ** it. Raise an error if __call metafield is not a function. |
| 295 | */ | 295 | */ |
| 296 | static void tryfuncTM (lua_State *L, StkId func) { | 296 | static void tryfuncTM (lua_State *L, StkId func) { |
| 297 | const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); | 297 | const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); |
| 298 | StkId p; | 298 | StkId p; |
| 299 | if (!ttisfunction(tm)) | 299 | if (!ttisfunction(tm)) |
| 300 | luaG_typeerror(L, func, "call"); | 300 | luaG_typeerror(L, s2v(func), "call"); |
| 301 | /* Open a hole inside the stack at 'func' */ | 301 | /* Open a hole inside the stack at 'func' */ |
| 302 | for (p = L->top; p > func; p--) | 302 | for (p = L->top; p > func; p--) |
| 303 | setobjs2s(L, p, p-1); | 303 | setobjs2s(L, p, p-1); |
| @@ -312,14 +312,15 @@ static void tryfuncTM (lua_State *L, StkId func) { | |||
| 312 | ** expressions, multiple results for tail calls/single parameters) | 312 | ** expressions, multiple results for tail calls/single parameters) |
| 313 | ** separated. | 313 | ** separated. |
| 314 | */ | 314 | */ |
| 315 | static int moveresults (lua_State *L, const TValue *firstResult, StkId res, | 315 | static int moveresults (lua_State *L, StkId firstResult, StkId res, |
| 316 | int nres, int wanted) { | 316 | int nres, int wanted) { |
| 317 | switch (wanted) { /* handle typical cases separately */ | 317 | switch (wanted) { /* handle typical cases separately */ |
| 318 | case 0: break; /* nothing to move */ | 318 | case 0: break; /* nothing to move */ |
| 319 | case 1: { /* one result needed */ | 319 | case 1: { /* one result needed */ |
| 320 | if (nres == 0) /* no results? */ | 320 | if (nres == 0) /* no results? */ |
| 321 | firstResult = luaO_nilobject; /* adjust with nil */ | 321 | setnilvalue(s2v(res)); /* adjust with nil */ |
| 322 | setobjs2s(L, res, firstResult); /* move it to proper place */ | 322 | else |
| 323 | setobjs2s(L, res, firstResult); /* move it to proper place */ | ||
| 323 | break; | 324 | break; |
| 324 | } | 325 | } |
| 325 | case LUA_MULTRET: { | 326 | case LUA_MULTRET: { |
| @@ -339,7 +340,7 @@ static int moveresults (lua_State *L, const TValue *firstResult, StkId res, | |||
| 339 | for (i = 0; i < nres; i++) /* move all results to correct place */ | 340 | for (i = 0; i < nres; i++) /* move all results to correct place */ |
| 340 | setobjs2s(L, res + i, firstResult + i); | 341 | setobjs2s(L, res + i, firstResult + i); |
| 341 | for (; i < wanted; i++) /* complete wanted number of results */ | 342 | for (; i < wanted; i++) /* complete wanted number of results */ |
| 342 | setnilvalue(res + i); | 343 | setnilvalue(s2v(res + i)); |
| 343 | } | 344 | } |
| 344 | break; | 345 | break; |
| 345 | } | 346 | } |
| @@ -385,13 +386,14 @@ int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { | |||
| 385 | */ | 386 | */ |
| 386 | int luaD_precall (lua_State *L, StkId func, int nresults) { | 387 | int luaD_precall (lua_State *L, StkId func, int nresults) { |
| 387 | lua_CFunction f; | 388 | lua_CFunction f; |
| 389 | TValue *funcv = s2v(func); | ||
| 388 | CallInfo *ci; | 390 | CallInfo *ci; |
| 389 | switch (ttype(func)) { | 391 | switch (ttype(funcv)) { |
| 390 | case LUA_TCCL: /* C closure */ | 392 | case LUA_TCCL: /* C closure */ |
| 391 | f = clCvalue(func)->f; | 393 | f = clCvalue(funcv)->f; |
| 392 | goto Cfunc; | 394 | goto Cfunc; |
| 393 | case LUA_TLCF: /* light C function */ | 395 | case LUA_TLCF: /* light C function */ |
| 394 | f = fvalue(func); | 396 | f = fvalue(funcv); |
| 395 | Cfunc: { | 397 | Cfunc: { |
| 396 | int n; /* number of returns */ | 398 | int n; /* number of returns */ |
| 397 | checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ | 399 | checkstackp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ |
| @@ -411,12 +413,12 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 411 | return 1; | 413 | return 1; |
| 412 | } | 414 | } |
| 413 | case LUA_TLCL: { /* Lua function: prepare its call */ | 415 | case LUA_TLCL: { /* Lua function: prepare its call */ |
| 414 | Proto *p = clLvalue(func)->p; | 416 | Proto *p = clLvalue(funcv)->p; |
| 415 | int n = cast_int(L->top - func) - 1; /* number of real arguments */ | 417 | int n = cast_int(L->top - func) - 1; /* number of real arguments */ |
| 416 | int fsize = p->maxstacksize; /* frame size */ | 418 | int fsize = p->maxstacksize; /* frame size */ |
| 417 | checkstackp(L, fsize, func); | 419 | checkstackp(L, fsize, func); |
| 418 | for (; n < p->numparams - p->is_vararg; n++) | 420 | for (; n < p->numparams - p->is_vararg; n++) |
| 419 | setnilvalue(L->top++); /* complete missing arguments */ | 421 | setnilvalue(s2v(L->top++)); /* complete missing arguments */ |
| 420 | if (p->is_vararg) | 422 | if (p->is_vararg) |
| 421 | luaT_adjustvarargs(L, p, n); | 423 | luaT_adjustvarargs(L, p, n); |
| 422 | ci = next_ci(L); /* now 'enter' new function */ | 424 | ci = next_ci(L); /* now 'enter' new function */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 2.30 2017/05/13 12:57:20 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 | */ |
| @@ -30,7 +30,7 @@ | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) |
| 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) | 33 | #define restorestack(L,n) ((StkId)((char *)L->stack + (n))) |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | /* macro to check stack size, preserving 'p' */ | 36 | /* macro to check stack size, preserving 'p' */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 2.49 2017/05/24 18:54:54 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 2.50 2017/06/27 11:35:31 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 | */ |
| @@ -61,9 +61,8 @@ UpVal *luaF_findupval (lua_State *L, StkId level) { | |||
| 61 | UpVal *p; | 61 | UpVal *p; |
| 62 | UpVal *uv; | 62 | UpVal *uv; |
| 63 | lua_assert(isintwups(L) || L->openupval == NULL); | 63 | lua_assert(isintwups(L) || L->openupval == NULL); |
| 64 | while ((p = *pp) != NULL && p->v >= level) { | 64 | while ((p = *pp) != NULL && uplevel(p) >= level) { |
| 65 | lua_assert(upisopen(p)); | 65 | if (uplevel(p) == level && !isdead(G(L), p)) /* corresponding upvalue? */ |
| 66 | if (p->v == level && !isdead(G(L), p)) /* corresponding upvalue? */ | ||
| 67 | return p; /* return it */ | 66 | return p; /* return it */ |
| 68 | pp = &p->u.open.next; | 67 | pp = &p->u.open.next; |
| 69 | } | 68 | } |
| @@ -75,7 +74,7 @@ UpVal *luaF_findupval (lua_State *L, StkId level) { | |||
| 75 | if (p) | 74 | if (p) |
| 76 | p->u.open.previous = &uv->u.open.next; | 75 | p->u.open.previous = &uv->u.open.next; |
| 77 | *pp = uv; | 76 | *pp = uv; |
| 78 | uv->v = level; /* current value lives in the stack */ | 77 | uv->v = s2v(level); /* current value lives in the stack */ |
| 79 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ | 78 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ |
| 80 | L->twups = G(L)->twups; /* link it to the list */ | 79 | L->twups = G(L)->twups; /* link it to the list */ |
| 81 | G(L)->twups = L; | 80 | G(L)->twups = L; |
| @@ -94,7 +93,8 @@ void luaF_unlinkupval (UpVal *uv) { | |||
| 94 | 93 | ||
| 95 | void luaF_close (lua_State *L, StkId level) { | 94 | void luaF_close (lua_State *L, StkId level) { |
| 96 | UpVal *uv; | 95 | UpVal *uv; |
| 97 | while (L->openupval != NULL && (uv = L->openupval)->v >= level) { | 96 | while (L->openupval != NULL && |
| 97 | (uv = L->openupval, uplevel(uv) >= level)) { | ||
| 98 | TValue *slot = &uv->u.value; /* new position for value */ | 98 | TValue *slot = &uv->u.value; /* new position for value */ |
| 99 | luaF_unlinkupval(uv); | 99 | luaF_unlinkupval(uv); |
| 100 | setobj(L, slot, uv->v); /* move value to upvalue slot */ | 100 | setobj(L, slot, uv->v); /* move value to upvalue slot */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.h,v 2.16 2017/04/11 18:41:09 roberto Exp roberto $ | 2 | ** $Id: lfunc.h,v 2.17 2017/05/04 13:32:01 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 | */ |
| @@ -32,6 +32,9 @@ | |||
| 32 | #define upisopen(up) ((up)->v != &(up)->u.value) | 32 | #define upisopen(up) ((up)->v != &(up)->u.value) |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v)) | ||
| 36 | |||
| 37 | |||
| 35 | /* | 38 | /* |
| 36 | ** maximum number of misses before giving up the cache of closures | 39 | ** maximum number of misses before giving up the cache of closures |
| 37 | ** in prototypes | 40 | ** in prototypes |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.231 2017/06/09 16:48:44 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.232 2017/06/12 14:21:44 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 | */ |
| @@ -575,11 +575,11 @@ static int traversethread (global_State *g, lua_State *th) { | |||
| 575 | lua_assert(g->gcstate == GCSatomic || | 575 | lua_assert(g->gcstate == GCSatomic || |
| 576 | th->openupval == NULL || isintwups(th)); | 576 | th->openupval == NULL || isintwups(th)); |
| 577 | for (; o < th->top; o++) /* mark live elements in the stack */ | 577 | for (; o < th->top; o++) /* mark live elements in the stack */ |
| 578 | markvalue(g, o); | 578 | markvalue(g, s2v(o)); |
| 579 | if (g->gcstate == GCSatomic) { /* final traversal? */ | 579 | if (g->gcstate == GCSatomic) { /* final traversal? */ |
| 580 | StkId lim = th->stack + th->stacksize; /* real end of stack */ | 580 | StkId lim = th->stack + th->stacksize; /* real end of stack */ |
| 581 | for (; o < lim; o++) /* clear not-marked stack slice */ | 581 | for (; o < lim; o++) /* clear not-marked stack slice */ |
| 582 | setnilvalue(o); | 582 | setnilvalue(s2v(o)); |
| 583 | /* 'remarkupvals' may have removed thread from 'twups' list */ | 583 | /* 'remarkupvals' may have removed thread from 'twups' list */ |
| 584 | if (!isintwups(th) && th->openupval != NULL) { | 584 | if (!isintwups(th) && th->openupval != NULL) { |
| 585 | th->twups = g->twups; /* link it back to the list */ | 585 | th->twups = g->twups; /* link it back to the list */ |
| @@ -872,8 +872,8 @@ static void GCTM (lua_State *L, int propagateerrors) { | |||
| 872 | g->gcrunning = running; /* restore state */ | 872 | g->gcrunning = running; /* restore state */ |
| 873 | if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ | 873 | if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ |
| 874 | if (status == LUA_ERRRUN) { /* is there an error object? */ | 874 | if (status == LUA_ERRRUN) { /* is there an error object? */ |
| 875 | const char *msg = (ttisstring(L->top - 1)) | 875 | const char *msg = (ttisstring(s2v(L->top - 1))) |
| 876 | ? svalue(L->top - 1) | 876 | ? svalue(s2v(L->top - 1)) |
| 877 | : "no message"; | 877 | : "no message"; |
| 878 | luaO_pushfstring(L, "error in __gc metamethod (%s)", msg); | 878 | luaO_pushfstring(L, "error in __gc metamethod (%s)", msg); |
| 879 | status = LUA_ERRGCMM; /* error in __gc metamethod */ | 879 | status = LUA_ERRGCMM; /* error in __gc metamethod */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.97 2017/06/09 16:48:44 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 | */ |
| @@ -129,7 +129,7 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { | |||
| 129 | TValue *o; /* entry for 'str' */ | 129 | TValue *o; /* entry for 'str' */ |
| 130 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ | 130 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 131 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ | 131 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
| 132 | o = luaH_set(L, ls->h, L->top - 1); | 132 | o = luaH_set(L, ls->h, s2v(L->top - 1)); |
| 133 | if (ttisnil(o)) { /* not in use yet? */ | 133 | if (ttisnil(o)) { /* not in use yet? */ |
| 134 | /* boolean value does not need GC barrier; | 134 | /* boolean value does not need GC barrier; |
| 135 | table is not a metatable, so it does not need to invalidate cache */ | 135 | table is not a metatable, so it does not need to invalidate cache */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.114 2017/04/19 16:34:35 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.115 2017/05/24 13:47:11 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 | */ |
| @@ -120,8 +120,8 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1, | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | 122 | ||
| 123 | void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | 123 | int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, |
| 124 | TValue *res) { | 124 | TValue *res) { |
| 125 | switch (op) { | 125 | switch (op) { |
| 126 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: | 126 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: |
| 127 | case LUA_OPSHL: case LUA_OPSHR: | 127 | case LUA_OPSHL: case LUA_OPSHR: |
| @@ -129,33 +129,40 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | |||
| 129 | lua_Integer i1; lua_Integer i2; | 129 | lua_Integer i1; lua_Integer i2; |
| 130 | if (tointeger(p1, &i1) && tointeger(p2, &i2)) { | 130 | if (tointeger(p1, &i1) && tointeger(p2, &i2)) { |
| 131 | setivalue(res, intarith(L, op, i1, i2)); | 131 | setivalue(res, intarith(L, op, i1, i2)); |
| 132 | return; | 132 | return 1; |
| 133 | } | 133 | } |
| 134 | else break; /* go to the end */ | 134 | else return 0; /* fail */ |
| 135 | } | 135 | } |
| 136 | case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */ | 136 | case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */ |
| 137 | lua_Number n1; lua_Number n2; | 137 | lua_Number n1; lua_Number n2; |
| 138 | if (tonumber(p1, &n1) && tonumber(p2, &n2)) { | 138 | if (tonumber(p1, &n1) && tonumber(p2, &n2)) { |
| 139 | setfltvalue(res, numarith(L, op, n1, n2)); | 139 | setfltvalue(res, numarith(L, op, n1, n2)); |
| 140 | return; | 140 | return 1; |
| 141 | } | 141 | } |
| 142 | else break; /* go to the end */ | 142 | else return 0; /* fail */ |
| 143 | } | 143 | } |
| 144 | default: { /* other operations */ | 144 | default: { /* other operations */ |
| 145 | lua_Number n1; lua_Number n2; | 145 | lua_Number n1; lua_Number n2; |
| 146 | if (ttisinteger(p1) && ttisinteger(p2)) { | 146 | if (ttisinteger(p1) && ttisinteger(p2)) { |
| 147 | setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2))); | 147 | setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2))); |
| 148 | return; | 148 | return 1; |
| 149 | } | 149 | } |
| 150 | else if (tonumber(p1, &n1) && tonumber(p2, &n2)) { | 150 | else if (tonumber(p1, &n1) && tonumber(p2, &n2)) { |
| 151 | setfltvalue(res, numarith(L, op, n1, n2)); | 151 | setfltvalue(res, numarith(L, op, n1, n2)); |
| 152 | return; | 152 | return 1; |
| 153 | } | 153 | } |
| 154 | else break; /* go to the end */ | 154 | else return 0; /* fail */ |
| 155 | } | 155 | } |
| 156 | } | 156 | } |
| 157 | /* could not perform raw operation; try metamethod */ | 157 | } |
| 158 | luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD)); | 158 | |
| 159 | |||
| 160 | void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, | ||
| 161 | StkId res) { | ||
| 162 | if (!luaO_rawarith(L, op, p1, p2, s2v(res))) { | ||
| 163 | /* could not perform raw operation; try metamethod */ | ||
| 164 | luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD)); | ||
| 165 | } | ||
| 159 | } | 166 | } |
| 160 | 167 | ||
| 161 | 168 | ||
| @@ -367,7 +374,7 @@ int luaO_utf8esc (char *buff, unsigned long x) { | |||
| 367 | /* | 374 | /* |
| 368 | ** Convert a number object to a string | 375 | ** Convert a number object to a string |
| 369 | */ | 376 | */ |
| 370 | void luaO_tostring (lua_State *L, StkId obj) { | 377 | void luaO_tostring (lua_State *L, TValue *obj) { |
| 371 | char buff[MAXNUMBER2STR]; | 378 | char buff[MAXNUMBER2STR]; |
| 372 | size_t len; | 379 | size_t len; |
| 373 | lua_assert(ttisnumber(obj)); | 380 | lua_assert(ttisnumber(obj)); |
| @@ -382,7 +389,7 @@ void luaO_tostring (lua_State *L, StkId obj) { | |||
| 382 | } | 389 | } |
| 383 | #endif | 390 | #endif |
| 384 | } | 391 | } |
| 385 | setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); | 392 | setsvalue(L, obj, luaS_newlstr(L, buff, len)); |
| 386 | } | 393 | } |
| 387 | 394 | ||
| 388 | 395 | ||
| @@ -418,18 +425,18 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
| 418 | break; | 425 | break; |
| 419 | } | 426 | } |
| 420 | case 'd': { /* an 'int' */ | 427 | case 'd': { /* an 'int' */ |
| 421 | setivalue(L->top, va_arg(argp, int)); | 428 | setivalue(s2v(L->top), va_arg(argp, int)); |
| 422 | goto top2str; | 429 | goto top2str; |
| 423 | } | 430 | } |
| 424 | case 'I': { /* a 'lua_Integer' */ | 431 | case 'I': { /* a 'lua_Integer' */ |
| 425 | setivalue(L->top, cast(lua_Integer, va_arg(argp, l_uacInt))); | 432 | setivalue(s2v(L->top), cast(lua_Integer, va_arg(argp, l_uacInt))); |
| 426 | goto top2str; | 433 | goto top2str; |
| 427 | } | 434 | } |
| 428 | case 'f': { /* a 'lua_Number' */ | 435 | case 'f': { /* a 'lua_Number' */ |
| 429 | setfltvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); | 436 | setfltvalue(s2v(L->top), cast_num(va_arg(argp, l_uacNumber))); |
| 430 | top2str: /* convert the top element to a string */ | 437 | top2str: /* convert the top element to a string */ |
| 431 | luaD_inctop(L); | 438 | luaD_inctop(L); |
| 432 | luaO_tostring(L, L->top - 1); | 439 | luaO_tostring(L, s2v(L->top - 1)); |
| 433 | break; | 440 | break; |
| 434 | } | 441 | } |
| 435 | case 'p': { /* a pointer */ | 442 | case 'p': { /* a pointer */ |
| @@ -460,7 +467,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
| 460 | luaD_checkstack(L, 1); | 467 | luaD_checkstack(L, 1); |
| 461 | pushstr(L, fmt, strlen(fmt)); | 468 | pushstr(L, fmt, strlen(fmt)); |
| 462 | if (n > 0) luaV_concat(L, n + 1); | 469 | if (n > 0) luaV_concat(L, n + 1); |
| 463 | return svalue(L->top - 1); | 470 | return svalue(s2v(L->top - 1)); |
| 464 | } | 471 | } |
| 465 | 472 | ||
| 466 | 473 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.123 2017/06/12 14:21:44 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.124 2017/06/27 11:35:31 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 | */ |
| @@ -110,7 +110,7 @@ typedef union Value { | |||
| 110 | #define TValuefields Value value_; lu_byte tt_ | 110 | #define TValuefields Value value_; lu_byte tt_ |
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | typedef struct lua_TValue { | 113 | typedef struct TValue { |
| 114 | TValuefields; | 114 | TValuefields; |
| 115 | } TValue; | 115 | } TValue; |
| 116 | 116 | ||
| @@ -282,13 +282,15 @@ typedef struct lua_TValue { | |||
| 282 | ** different types of assignments, according to destination | 282 | ** different types of assignments, according to destination |
| 283 | */ | 283 | */ |
| 284 | 284 | ||
| 285 | /* from stack to (same) stack */ | 285 | /* from stack to stack */ |
| 286 | #define setobjs2s setobj | 286 | #define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2)) |
| 287 | /* to stack (not from same stack) */ | 287 | /* to stack (not from same stack) */ |
| 288 | #define setobj2s setobj | 288 | #define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2) |
| 289 | #define setsvalue2s setsvalue | 289 | #define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s) |
| 290 | #define sethvalue2s sethvalue | 290 | #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h) |
| 291 | #define setptvalue2s setptvalue | 291 | #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t) |
| 292 | #define setptvalue2s(L,o,p) setptvalue(L,s2v(o),p) | ||
| 293 | #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl) | ||
| 292 | /* from table to same table */ | 294 | /* from table to same table */ |
| 293 | #define setobjt2t setobj | 295 | #define setobjt2t setobj |
| 294 | /* to new object */ | 296 | /* to new object */ |
| @@ -307,9 +309,16 @@ typedef struct lua_TValue { | |||
| 307 | */ | 309 | */ |
| 308 | 310 | ||
| 309 | 311 | ||
| 310 | typedef TValue *StkId; /* index to stack elements */ | 312 | typedef union StackValue { |
| 313 | TValue val; | ||
| 314 | } StackValue; | ||
| 311 | 315 | ||
| 312 | 316 | ||
| 317 | typedef StackValue *StkId; /* index to stack elements */ | ||
| 318 | |||
| 319 | /* convert a 'StackValue' to a 'TValue' */ | ||
| 320 | #define s2v(o) (&(o)->val) | ||
| 321 | |||
| 313 | 322 | ||
| 314 | 323 | ||
| 315 | /* | 324 | /* |
| @@ -620,11 +629,13 @@ LUAI_FUNC int luaO_int2fb (unsigned int x); | |||
| 620 | LUAI_FUNC int luaO_fb2int (int x); | 629 | LUAI_FUNC int luaO_fb2int (int x); |
| 621 | LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); | 630 | LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); |
| 622 | LUAI_FUNC int luaO_ceillog2 (unsigned int x); | 631 | LUAI_FUNC int luaO_ceillog2 (unsigned int x); |
| 632 | LUAI_FUNC int luaO_rawarith (lua_State *L, int op, const TValue *p1, | ||
| 633 | const TValue *p2, TValue *res); | ||
| 623 | LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, | 634 | LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, |
| 624 | const TValue *p2, TValue *res); | 635 | const TValue *p2, StkId res); |
| 625 | LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); | 636 | LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); |
| 626 | LUAI_FUNC int luaO_hexavalue (int c); | 637 | LUAI_FUNC int luaO_hexavalue (int c); |
| 627 | LUAI_FUNC void luaO_tostring (lua_State *L, StkId obj); | 638 | LUAI_FUNC void luaO_tostring (lua_State *L, TValue *obj); |
| 628 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 639 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
| 629 | va_list argp); | 640 | va_list argp); |
| 630 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); | 641 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.159 2017/05/13 12:57:20 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.160 2017/06/27 11:35:31 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 | */ |
| @@ -1650,10 +1650,10 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | |||
| 1650 | LexState lexstate; | 1650 | LexState lexstate; |
| 1651 | FuncState funcstate; | 1651 | FuncState funcstate; |
| 1652 | LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */ | 1652 | LClosure *cl = luaF_newLclosure(L, 1); /* create main closure */ |
| 1653 | setclLvalue(L, L->top, cl); /* anchor it (to avoid being collected) */ | 1653 | setclLvalue2s(L, L->top, cl); /* anchor it (to avoid being collected) */ |
| 1654 | luaD_inctop(L); | 1654 | luaD_inctop(L); |
| 1655 | lexstate.h = luaH_new(L); /* create table for scanner */ | 1655 | lexstate.h = luaH_new(L); /* create table for scanner */ |
| 1656 | sethvalue(L, L->top, lexstate.h); /* anchor it */ | 1656 | sethvalue2s(L, L->top, lexstate.h); /* anchor it */ |
| 1657 | luaD_inctop(L); | 1657 | luaD_inctop(L); |
| 1658 | funcstate.f = cl->p = luaF_newproto(L); | 1658 | funcstate.f = cl->p = luaF_newproto(L); |
| 1659 | funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ | 1659 | funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.139 2017/05/04 13:32:01 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.140 2017/05/26 19:14:29 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 | */ |
| @@ -143,10 +143,10 @@ void luaE_shrinkCI (lua_State *L) { | |||
| 143 | static void stack_init (lua_State *L1, lua_State *L) { | 143 | static void stack_init (lua_State *L1, lua_State *L) { |
| 144 | int i; CallInfo *ci; | 144 | int i; CallInfo *ci; |
| 145 | /* initialize stack array */ | 145 | /* initialize stack array */ |
| 146 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue); | 146 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, StackValue); |
| 147 | L1->stacksize = BASIC_STACK_SIZE; | 147 | L1->stacksize = BASIC_STACK_SIZE; |
| 148 | for (i = 0; i < BASIC_STACK_SIZE; i++) | 148 | for (i = 0; i < BASIC_STACK_SIZE; i++) |
| 149 | setnilvalue(L1->stack + i); /* erase new stack */ | 149 | setnilvalue(s2v(L1->stack + i)); /* erase new stack */ |
| 150 | L1->top = L1->stack; | 150 | L1->top = L1->stack; |
| 151 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; | 151 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; |
| 152 | /* initialize first ci */ | 152 | /* initialize first ci */ |
| @@ -154,7 +154,7 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
| 154 | ci->next = ci->previous = NULL; | 154 | ci->next = ci->previous = NULL; |
| 155 | ci->callstatus = 0; | 155 | ci->callstatus = 0; |
| 156 | ci->func = L1->top; | 156 | ci->func = L1->top; |
| 157 | setnilvalue(L1->top++); /* 'function' entry for this 'ci' */ | 157 | setnilvalue(s2v(L1->top++)); /* 'function' entry for this 'ci' */ |
| 158 | ci->top = L1->top + LUA_MINSTACK; | 158 | ci->top = L1->top + LUA_MINSTACK; |
| 159 | L1->ci = ci; | 159 | L1->ci = ci; |
| 160 | } | 160 | } |
| @@ -258,7 +258,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { | |||
| 258 | L1->next = g->allgc; | 258 | L1->next = g->allgc; |
| 259 | g->allgc = obj2gco(L1); | 259 | g->allgc = obj2gco(L1); |
| 260 | /* anchor it on L stack */ | 260 | /* anchor it on L stack */ |
| 261 | setthvalue(L, L->top, L1); | 261 | setthvalue2s(L, L->top, L1); |
| 262 | api_incr_top(L); | 262 | api_incr_top(L); |
| 263 | preinit_thread(L1, g); | 263 | preinit_thread(L1, g); |
| 264 | L1->hookmask = L->hookmask; | 264 | L1->hookmask = L->hookmask; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.123 2017/06/09 16:48:44 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.124 2017/06/12 14:21: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 | */ |
| @@ -211,7 +211,7 @@ static unsigned int arrayindex (lua_Integer k) { | |||
| 211 | ** elements in the array part, then elements in the hash part. The | 211 | ** elements in the array part, then elements in the hash part. The |
| 212 | ** beginning of a traversal is signaled by 0. | 212 | ** beginning of a traversal is signaled by 0. |
| 213 | */ | 213 | */ |
| 214 | static unsigned int findindex (lua_State *L, Table *t, StkId key) { | 214 | static unsigned int findindex (lua_State *L, Table *t, TValue *key) { |
| 215 | unsigned int i; | 215 | unsigned int i; |
| 216 | if (ttisnil(key)) return 0; /* first iteration */ | 216 | if (ttisnil(key)) return 0; /* first iteration */ |
| 217 | i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; | 217 | i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; |
| @@ -229,18 +229,18 @@ static unsigned int findindex (lua_State *L, Table *t, StkId key) { | |||
| 229 | 229 | ||
| 230 | 230 | ||
| 231 | int luaH_next (lua_State *L, Table *t, StkId key) { | 231 | int luaH_next (lua_State *L, Table *t, StkId key) { |
| 232 | unsigned int i = findindex(L, t, key); /* find original element */ | 232 | unsigned int i = findindex(L, t, s2v(key)); /* find original element */ |
| 233 | for (; i < t->sizearray; i++) { /* try first array part */ | 233 | for (; i < t->sizearray; i++) { /* try first array part */ |
| 234 | if (!ttisnil(&t->array[i])) { /* a non-nil value? */ | 234 | if (!ttisnil(&t->array[i])) { /* a non-nil value? */ |
| 235 | setivalue(key, i + 1); | 235 | setivalue(s2v(key), i + 1); |
| 236 | setobj2s(L, key+1, &t->array[i]); | 236 | setobj2s(L, key + 1, &t->array[i]); |
| 237 | return 1; | 237 | return 1; |
| 238 | } | 238 | } |
| 239 | } | 239 | } |
| 240 | for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) { /* hash part */ | 240 | for (i -= t->sizearray; cast_int(i) < sizenode(t); i++) { /* hash part */ |
| 241 | if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ | 241 | if (!ttisnil(gval(gnode(t, i)))) { /* a non-nil value? */ |
| 242 | Node *n = gnode(t, i); | 242 | Node *n = gnode(t, i); |
| 243 | getnodekey(L, key, n); | 243 | getnodekey(L, s2v(key), n); |
| 244 | setobj2s(L, key + 1, gval(n)); | 244 | setobj2s(L, key + 1, gval(n)); |
| 245 | return 1; | 245 | return 1; |
| 246 | } | 246 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.221 2017/06/27 11:35:31 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.222 2017/06/27 18:32:49 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 | */ |
| @@ -46,7 +46,7 @@ void *l_Trick = 0; | |||
| 46 | int islocked = 0; | 46 | int islocked = 0; |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | #define obj_at(L,k) (L->ci->func + (k)) | 49 | #define obj_at(L,k) s2v(L->ci->func + (k)) |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | static int runC (lua_State *L, lua_State *L1, const char *pc); | 52 | static int runC (lua_State *L, lua_State *L1, const char *pc); |
| @@ -316,7 +316,7 @@ static int lua_checkpc (lua_State *L, CallInfo *ci) { | |||
| 316 | StkId f = (L->status != LUA_YIELD || ci != L->ci) | 316 | StkId f = (L->status != LUA_YIELD || ci != L->ci) |
| 317 | ? ci->func | 317 | ? ci->func |
| 318 | : restorestack(L, ci->extra); | 318 | : restorestack(L, ci->extra); |
| 319 | Proto *p = clLvalue(f)->p; | 319 | Proto *p = clLvalue(s2v(f))->p; |
| 320 | return p->code <= ci->u.l.savedpc && | 320 | return p->code <= ci->u.l.savedpc && |
| 321 | ci->u.l.savedpc <= p->code + p->sizecode; | 321 | ci->u.l.savedpc <= p->code + p->sizecode; |
| 322 | } | 322 | } |
| @@ -336,7 +336,7 @@ static void checkstack (global_State *g, lua_State *L1) { | |||
| 336 | } | 336 | } |
| 337 | if (L1->stack) { /* complete thread? */ | 337 | if (L1->stack) { /* complete thread? */ |
| 338 | for (o = L1->stack; o < L1->stack_last + EXTRA_STACK; o++) | 338 | for (o = L1->stack; o < L1->stack_last + EXTRA_STACK; o++) |
| 339 | checkliveness(L1, o); /* entire stack must have valid values */ | 339 | checkliveness(L1, s2v(o)); /* entire stack must have valid values */ |
| 340 | } | 340 | } |
| 341 | else lua_assert(L1->stacksize == 0); | 341 | else lua_assert(L1->stacksize == 0); |
| 342 | } | 342 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 2.40 2017/05/08 15:57:23 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.41 2017/05/13 12:57:20 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 | */ |
| @@ -100,24 +100,36 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) { | |||
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, |
| 103 | const TValue *p2, TValue *p3, int hasres) { | 103 | const TValue *p2, const TValue *p3) { |
| 104 | ptrdiff_t result = savestack(L, p3); | 104 | StkId func = L->top; |
| 105 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ | ||
| 106 | setobj2s(L, func + 1, p1); /* 1st argument */ | ||
| 107 | setobj2s(L, func + 2, p2); /* 2nd argument */ | ||
| 108 | setobj2s(L, func + 3, p3); /* 3rd argument */ | ||
| 109 | L->top += 4; | ||
| 110 | /* metamethod may yield only when called from Lua code */ | ||
| 111 | if (isLua(L->ci)) | ||
| 112 | luaD_call(L, func, 0); | ||
| 113 | else | ||
| 114 | luaD_callnoyield(L, func, 0); | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, | ||
| 119 | const TValue *p2, StkId res) { | ||
| 120 | ptrdiff_t result = savestack(L, res); | ||
| 105 | StkId func = L->top; | 121 | StkId func = L->top; |
| 106 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ | 122 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ |
| 107 | setobj2s(L, func + 1, p1); /* 1st argument */ | 123 | setobj2s(L, func + 1, p1); /* 1st argument */ |
| 108 | setobj2s(L, func + 2, p2); /* 2nd argument */ | 124 | setobj2s(L, func + 2, p2); /* 2nd argument */ |
| 109 | L->top += 3; | 125 | L->top += 3; |
| 110 | if (!hasres) /* no result? 'p3' is third argument */ | ||
| 111 | setobj2s(L, L->top++, p3); /* 3rd argument */ | ||
| 112 | /* metamethod may yield only when called from Lua code */ | 126 | /* metamethod may yield only when called from Lua code */ |
| 113 | if (isLua(L->ci)) | 127 | if (isLua(L->ci)) |
| 114 | luaD_call(L, func, hasres); | 128 | luaD_call(L, func, 1); |
| 115 | else | 129 | else |
| 116 | luaD_callnoyield(L, func, hasres); | 130 | luaD_callnoyield(L, func, 1); |
| 117 | if (hasres) { /* if has result, move it to its place */ | 131 | res = restorestack(L, result); |
| 118 | p3 = restorestack(L, result); | 132 | setobjs2s(L, res, --L->top); /* more result to its place */ |
| 119 | setobjs2s(L, p3, --L->top); | ||
| 120 | } | ||
| 121 | } | 133 | } |
| 122 | 134 | ||
| 123 | 135 | ||
| @@ -127,7 +139,7 @@ static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2, | |||
| 127 | if (ttisnil(tm)) | 139 | if (ttisnil(tm)) |
| 128 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ | 140 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ |
| 129 | if (ttisnil(tm)) return 0; | 141 | if (ttisnil(tm)) return 0; |
| 130 | luaT_callTM(L, tm, p1, p2, res, 1); | 142 | luaT_callTMres(L, tm, p1, p2, res); |
| 131 | return 1; | 143 | return 1; |
| 132 | } | 144 | } |
| 133 | 145 | ||
| @@ -160,7 +172,7 @@ int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, | |||
| 160 | if (!callbinTM(L, p1, p2, L->top, event)) | 172 | if (!callbinTM(L, p1, p2, L->top, event)) |
| 161 | return -1; /* no metamethod */ | 173 | return -1; /* no metamethod */ |
| 162 | else | 174 | else |
| 163 | return !l_isfalse(L->top); | 175 | return !l_isfalse(s2v(L->top)); |
| 164 | } | 176 | } |
| 165 | 177 | ||
| 166 | 178 | ||
| @@ -171,19 +183,19 @@ void luaT_adjustvarargs (lua_State *L, Proto *p, int actual) { | |||
| 171 | int nfixparams = p->numparams - 1; /* number of fixed parameters */ | 183 | int nfixparams = p->numparams - 1; /* number of fixed parameters */ |
| 172 | actual -= nfixparams; /* number of extra arguments */ | 184 | actual -= nfixparams; /* number of extra arguments */ |
| 173 | vtab = luaH_new(L); /* create vararg table */ | 185 | vtab = luaH_new(L); /* create vararg table */ |
| 174 | sethvalue(L, L->top, vtab); /* anchor it for resizing */ | 186 | sethvalue2s(L, L->top, vtab); /* anchor it for resizing */ |
| 175 | L->top++; /* space ensured by caller */ | 187 | L->top++; /* space ensured by caller */ |
| 176 | luaH_resize(L, vtab, actual, 1); | 188 | luaH_resize(L, vtab, actual, 1); |
| 177 | for (i = 0; i < actual; i++) /* put extra arguments into vararg table */ | 189 | for (i = 0; i < actual; i++) /* put extra arguments into vararg table */ |
| 178 | setobj2n(L, &vtab->array[i], L->top - actual + i - 1); | 190 | setobj2n(L, &vtab->array[i], s2v(L->top - actual + i - 1)); |
| 179 | setsvalue(L, &nname, luaS_newliteral(L, "n")); /* get field 'n' */ | 191 | setsvalue(L, &nname, luaS_newliteral(L, "n")); /* get field 'n' */ |
| 180 | setivalue(luaH_set(L, vtab, &nname), actual); /* store counter there */ | 192 | setivalue(luaH_set(L, vtab, &nname), actual); /* store counter there */ |
| 181 | L->top -= actual; /* remove extra elements from the stack */ | 193 | L->top -= actual; /* remove extra elements from the stack */ |
| 182 | sethvalue(L, L->top - 1, vtab); /* move table to new top */ | 194 | sethvalue2s(L, L->top - 1, vtab); /* move table to new top */ |
| 183 | } | 195 | } |
| 184 | 196 | ||
| 185 | 197 | ||
| 186 | void luaT_getvarargs (lua_State *L, StkId t, StkId where, int wanted) { | 198 | void luaT_getvarargs (lua_State *L, TValue *t, StkId where, int wanted) { |
| 187 | if (!ttistable(t)) | 199 | if (!ttistable(t)) |
| 188 | luaG_runerror(L, "'vararg' parameter is not a table"); | 200 | luaG_runerror(L, "'vararg' parameter is not a table"); |
| 189 | else { | 201 | else { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 2.23 2017/05/08 15:57:23 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.24 2017/05/13 12:57:20 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 | */ |
| @@ -63,14 +63,16 @@ LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, | |||
| 63 | LUAI_FUNC void luaT_init (lua_State *L); | 63 | LUAI_FUNC void luaT_init (lua_State *L); |
| 64 | 64 | ||
| 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, |
| 66 | const TValue *p2, TValue *p3, int hasres); | 66 | const TValue *p2, const TValue *p3); |
| 67 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, | ||
| 68 | const TValue *p1, const TValue *p2, StkId p3); | ||
| 67 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, | 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, |
| 68 | StkId res, TMS event); | 70 | StkId res, TMS event); |
| 69 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, | 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, |
| 70 | const TValue *p2, TMS event); | 72 | const TValue *p2, TMS event); |
| 71 | 73 | ||
| 72 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, Proto *p, int actual); | 74 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, Proto *p, int actual); |
| 73 | LUAI_FUNC void luaT_getvarargs (lua_State *L, StkId t, StkId where, | 75 | LUAI_FUNC void luaT_getvarargs (lua_State *L, TValue *t, StkId where, |
| 74 | int wanted); | 76 | int wanted); |
| 75 | 77 | ||
| 76 | 78 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 2.45 2017/06/27 11:35:31 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.46 2017/06/27 14:21:12 roberto Exp roberto $ |
| 3 | ** load precompiled Lua chunks | 3 | ** load precompiled Lua chunks |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -283,7 +283,7 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { | |||
| 283 | S.Z = Z; | 283 | S.Z = Z; |
| 284 | checkHeader(&S); | 284 | checkHeader(&S); |
| 285 | cl = luaF_newLclosure(L, LoadByte(&S)); | 285 | cl = luaF_newLclosure(L, LoadByte(&S)); |
| 286 | setclLvalue(L, L->top, cl); | 286 | setclLvalue2s(L, L->top, cl); |
| 287 | luaD_inctop(L); | 287 | luaD_inctop(L); |
| 288 | cl->p = luaF_newproto(L); | 288 | cl->p = luaF_newproto(L); |
| 289 | LoadFunction(&S, cl->p, NULL); | 289 | LoadFunction(&S, cl->p, NULL); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.286 2017/06/01 20:22:33 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.287 2017/06/09 19:16:41 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 | */ |
| @@ -172,13 +172,13 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
| 172 | lua_assert(ttisnil(slot)); | 172 | lua_assert(ttisnil(slot)); |
| 173 | tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ | 173 | tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ |
| 174 | if (tm == NULL) { /* no metamethod? */ | 174 | if (tm == NULL) { /* no metamethod? */ |
| 175 | setnilvalue(val); /* result is nil */ | 175 | setnilvalue(s2v(val)); /* result is nil */ |
| 176 | return; | 176 | return; |
| 177 | } | 177 | } |
| 178 | /* else will try the metamethod */ | 178 | /* else will try the metamethod */ |
| 179 | } | 179 | } |
| 180 | if (ttisfunction(tm)) { /* is metamethod a function? */ | 180 | if (ttisfunction(tm)) { /* is metamethod a function? */ |
| 181 | luaT_callTM(L, tm, t, key, val, 1); /* call it */ | 181 | luaT_callTMres(L, tm, t, key, val); /* call it */ |
| 182 | return; | 182 | return; |
| 183 | } | 183 | } |
| 184 | t = tm; /* else try to access 'tm[key]' */ | 184 | t = tm; /* else try to access 'tm[key]' */ |
| @@ -200,7 +200,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
| 200 | ** would have done the job.) | 200 | ** would have done the job.) |
| 201 | */ | 201 | */ |
| 202 | void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | 202 | void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |
| 203 | StkId val, const TValue *slot) { | 203 | TValue *val, const TValue *slot) { |
| 204 | int loop; /* counter to avoid infinite loops */ | 204 | int loop; /* counter to avoid infinite loops */ |
| 205 | for (loop = 0; loop < MAXTAGLOOP; loop++) { | 205 | for (loop = 0; loop < MAXTAGLOOP; loop++) { |
| 206 | const TValue *tm; /* '__newindex' metamethod */ | 206 | const TValue *tm; /* '__newindex' metamethod */ |
| @@ -225,7 +225,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | |||
| 225 | } | 225 | } |
| 226 | /* try the metamethod */ | 226 | /* try the metamethod */ |
| 227 | if (ttisfunction(tm)) { | 227 | if (ttisfunction(tm)) { |
| 228 | luaT_callTM(L, tm, t, key, val, 0); | 228 | luaT_callTM(L, tm, t, key, val); |
| 229 | return; | 229 | return; |
| 230 | } | 230 | } |
| 231 | t = tm; /* else repeat assignment over 'tm' */ | 231 | t = tm; /* else repeat assignment over 'tm' */ |
| @@ -446,8 +446,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 446 | } | 446 | } |
| 447 | if (tm == NULL) /* no TM? */ | 447 | if (tm == NULL) /* no TM? */ |
| 448 | return 0; /* objects are different */ | 448 | return 0; /* objects are different */ |
| 449 | luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */ | 449 | luaT_callTMres(L, tm, t1, t2, L->top); /* call TM */ |
| 450 | return !l_isfalse(L->top); | 450 | return !l_isfalse(s2v(L->top)); |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | 453 | ||
| @@ -461,8 +461,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 461 | static void copy2buff (StkId top, int n, char *buff) { | 461 | static void copy2buff (StkId top, int n, char *buff) { |
| 462 | size_t tl = 0; /* size already copied */ | 462 | size_t tl = 0; /* size already copied */ |
| 463 | do { | 463 | do { |
| 464 | size_t l = vslen(top - n); /* length of string being copied */ | 464 | size_t l = vslen(s2v(top - n)); /* length of string being copied */ |
| 465 | memcpy(buff + tl, svalue(top - n), l * sizeof(char)); | 465 | memcpy(buff + tl, svalue(s2v(top - n)), l * sizeof(char)); |
| 466 | tl += l; | 466 | tl += l; |
| 467 | } while (--n > 0); | 467 | } while (--n > 0); |
| 468 | } | 468 | } |
| @@ -477,20 +477,21 @@ void luaV_concat (lua_State *L, int total) { | |||
| 477 | do { | 477 | do { |
| 478 | StkId top = L->top; | 478 | StkId top = L->top; |
| 479 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 479 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
| 480 | if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1)) | 480 | if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) || |
| 481 | luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT); | 481 | !tostring(L, s2v(top - 1))) |
| 482 | else if (isemptystr(top - 1)) /* second operand is empty? */ | 482 | luaT_trybinTM(L, s2v(top - 2), s2v(top - 1), top - 2, TM_CONCAT); |
| 483 | cast_void(tostring(L, top - 2)); /* result is first operand */ | 483 | else if (isemptystr(s2v(top - 1))) /* second operand is empty? */ |
| 484 | else if (isemptystr(top - 2)) { /* first operand is an empty string? */ | 484 | cast_void(tostring(L, s2v(top - 2))); /* result is first operand */ |
| 485 | else if (isemptystr(s2v(top - 2))) { /* first operand is empty string? */ | ||
| 485 | setobjs2s(L, top - 2, top - 1); /* result is second op. */ | 486 | setobjs2s(L, top - 2, top - 1); /* result is second op. */ |
| 486 | } | 487 | } |
| 487 | else { | 488 | else { |
| 488 | /* at least two non-empty string values; get as many as possible */ | 489 | /* at least two non-empty string values; get as many as possible */ |
| 489 | size_t tl = vslen(top - 1); | 490 | size_t tl = vslen(s2v(top - 1)); |
| 490 | TString *ts; | 491 | TString *ts; |
| 491 | /* collect total length and number of strings */ | 492 | /* collect total length and number of strings */ |
| 492 | for (n = 1; n < total && tostring(L, top - n - 1); n++) { | 493 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { |
| 493 | size_t l = vslen(top - n - 1); | 494 | size_t l = vslen(s2v(top - n - 1)); |
| 494 | if (l >= (MAX_SIZE/sizeof(char)) - tl) | 495 | if (l >= (MAX_SIZE/sizeof(char)) - tl) |
| 495 | luaG_runerror(L, "string length overflow"); | 496 | luaG_runerror(L, "string length overflow"); |
| 496 | tl += l; | 497 | tl += l; |
| @@ -522,15 +523,15 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
| 522 | Table *h = hvalue(rb); | 523 | Table *h = hvalue(rb); |
| 523 | tm = fasttm(L, h->metatable, TM_LEN); | 524 | tm = fasttm(L, h->metatable, TM_LEN); |
| 524 | if (tm) break; /* metamethod? break switch to call it */ | 525 | if (tm) break; /* metamethod? break switch to call it */ |
| 525 | setivalue(ra, luaH_getn(h)); /* else primitive len */ | 526 | setivalue(s2v(ra), luaH_getn(h)); /* else primitive len */ |
| 526 | return; | 527 | return; |
| 527 | } | 528 | } |
| 528 | case LUA_TSHRSTR: { | 529 | case LUA_TSHRSTR: { |
| 529 | setivalue(ra, tsvalue(rb)->shrlen); | 530 | setivalue(s2v(ra), tsvalue(rb)->shrlen); |
| 530 | return; | 531 | return; |
| 531 | } | 532 | } |
| 532 | case LUA_TLNGSTR: { | 533 | case LUA_TLNGSTR: { |
| 533 | setivalue(ra, tsvalue(rb)->u.lnglen); | 534 | setivalue(s2v(ra), tsvalue(rb)->u.lnglen); |
| 534 | return; | 535 | return; |
| 535 | } | 536 | } |
| 536 | default: { /* try metamethod */ | 537 | default: { /* try metamethod */ |
| @@ -540,7 +541,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
| 540 | break; | 541 | break; |
| 541 | } | 542 | } |
| 542 | } | 543 | } |
| 543 | luaT_callTM(L, tm, rb, rb, ra, 1); | 544 | luaT_callTMres(L, tm, rb, rb, ra); |
| 544 | } | 545 | } |
| 545 | 546 | ||
| 546 | 547 | ||
| @@ -615,7 +616,7 @@ static LClosure *getcached (Proto *p, UpVal **encup, StkId base) { | |||
| 615 | Upvaldesc *uv = p->upvalues; | 616 | Upvaldesc *uv = p->upvalues; |
| 616 | int i; | 617 | int i; |
| 617 | for (i = 0; i < nup; i++) { /* check whether it has right upvalues */ | 618 | for (i = 0; i < nup; i++) { /* check whether it has right upvalues */ |
| 618 | TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v; | 619 | TValue *v = uv[i].instack ? s2v(base + uv[i].idx) : encup[uv[i].idx]->v; |
| 619 | if (c->upvals[i]->v != v) | 620 | if (c->upvals[i]->v != v) |
| 620 | return NULL; /* wrong upvalue; cannot reuse closure */ | 621 | return NULL; /* wrong upvalue; cannot reuse closure */ |
| 621 | } | 622 | } |
| @@ -636,7 +637,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, | |||
| 636 | int i; | 637 | int i; |
| 637 | LClosure *ncl = luaF_newLclosure(L, nup); | 638 | LClosure *ncl = luaF_newLclosure(L, nup); |
| 638 | ncl->p = p; | 639 | ncl->p = p; |
| 639 | setclLvalue(L, ra, ncl); /* anchor new closure in stack */ | 640 | setclLvalue2s(L, ra, ncl); /* anchor new closure in stack */ |
| 640 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ | 641 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ |
| 641 | if (uv[i].instack) /* upvalue refers to local variable? */ | 642 | if (uv[i].instack) /* upvalue refers to local variable? */ |
| 642 | ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx); | 643 | ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx); |
| @@ -674,7 +675,7 @@ void luaV_finishOp (lua_State *L) { | |||
| 674 | break; | 675 | break; |
| 675 | } | 676 | } |
| 676 | case OP_LE: case OP_LT: case OP_EQ: { | 677 | case OP_LE: case OP_LT: case OP_EQ: { |
| 677 | int res = !l_isfalse(L->top - 1); | 678 | int res = !l_isfalse(s2v(L->top - 1)); |
| 678 | L->top--; | 679 | L->top--; |
| 679 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ | 680 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ |
| 680 | lua_assert(op == OP_LE); | 681 | lua_assert(op == OP_LE); |
| @@ -734,13 +735,15 @@ void luaV_finishOp (lua_State *L) { | |||
| 734 | 735 | ||
| 735 | #define RA(i) (base+GETARG_A(i)) | 736 | #define RA(i) (base+GETARG_A(i)) |
| 736 | #define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_Br(i)) | 737 | #define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_Br(i)) |
| 738 | #define vRB(i) s2v(RB(i)) | ||
| 737 | #define KB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_B(i)) | 739 | #define KB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_B(i)) |
| 738 | #define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) | 740 | #define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) |
| 741 | #define vRC(i) s2v(RC(i)) | ||
| 739 | #define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i)) | 742 | #define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i)) |
| 740 | #define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ | 743 | #define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \ |
| 741 | (GETARG_Bk(i)) ? k + GETARG_Br(i) : base + GETARG_Br(i)) | 744 | (GETARG_Bk(i)) ? k + GETARG_Br(i) : s2v(base + GETARG_Br(i))) |
| 742 | #define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ | 745 | #define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ |
| 743 | (GETARG_Ck(i)) ? k + GETARG_Cr(i) : base + GETARG_Cr(i)) | 746 | (GETARG_Ck(i)) ? k + GETARG_Cr(i) : s2v(base + GETARG_Cr(i))) |
| 744 | 747 | ||
| 745 | 748 | ||
| 746 | 749 | ||
| @@ -803,7 +806,7 @@ void luaV_execute (lua_State *L) { | |||
| 803 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ | 806 | ci->callstatus |= CIST_FRESH; /* fresh invocation of 'luaV_execute" */ |
| 804 | newframe: /* reentry point when frame changes (call/return) */ | 807 | newframe: /* reentry point when frame changes (call/return) */ |
| 805 | lua_assert(ci == L->ci); | 808 | lua_assert(ci == L->ci); |
| 806 | cl = clLvalue(ci->func); /* local reference to function's closure */ | 809 | cl = clLvalue(s2v(ci->func)); /* local reference to function's closure */ |
| 807 | k = cl->p->k; /* local reference to function's constant table */ | 810 | k = cl->p->k; /* local reference to function's constant table */ |
| 808 | updatemask(L); | 811 | updatemask(L); |
| 809 | base = ci->func + 1; | 812 | base = ci->func + 1; |
| @@ -827,7 +830,7 @@ void luaV_execute (lua_State *L) { | |||
| 827 | } | 830 | } |
| 828 | vmcase(OP_LOADI) { | 831 | vmcase(OP_LOADI) { |
| 829 | lua_Integer b = GETARG_sBx(i); | 832 | lua_Integer b = GETARG_sBx(i); |
| 830 | setivalue(ra, b); | 833 | setivalue(s2v(ra), b); |
| 831 | vmbreak; | 834 | vmbreak; |
| 832 | } | 835 | } |
| 833 | vmcase(OP_LOADKX) { | 836 | vmcase(OP_LOADKX) { |
| @@ -838,14 +841,14 @@ void luaV_execute (lua_State *L) { | |||
| 838 | vmbreak; | 841 | vmbreak; |
| 839 | } | 842 | } |
| 840 | vmcase(OP_LOADBOOL) { | 843 | vmcase(OP_LOADBOOL) { |
| 841 | setbvalue(ra, GETARG_B(i)); | 844 | setbvalue(s2v(ra), GETARG_B(i)); |
| 842 | if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ | 845 | if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ |
| 843 | vmbreak; | 846 | vmbreak; |
| 844 | } | 847 | } |
| 845 | vmcase(OP_LOADNIL) { | 848 | vmcase(OP_LOADNIL) { |
| 846 | int b = GETARG_B(i); | 849 | int b = GETARG_B(i); |
| 847 | do { | 850 | do { |
| 848 | setnilvalue(ra++); | 851 | setnilvalue(s2v(ra++)); |
| 849 | } while (b--); | 852 | } while (b--); |
| 850 | vmbreak; | 853 | vmbreak; |
| 851 | } | 854 | } |
| @@ -856,8 +859,8 @@ void luaV_execute (lua_State *L) { | |||
| 856 | } | 859 | } |
| 857 | vmcase(OP_SETUPVAL) { | 860 | vmcase(OP_SETUPVAL) { |
| 858 | UpVal *uv = cl->upvals[GETARG_B(i)]; | 861 | UpVal *uv = cl->upvals[GETARG_B(i)]; |
| 859 | setobj(L, uv->v, ra); | 862 | setobj(L, uv->v, s2v(ra)); |
| 860 | luaC_barrier(L, uv, ra); | 863 | luaC_barrier(L, uv, s2v(ra)); |
| 861 | vmbreak; | 864 | vmbreak; |
| 862 | } | 865 | } |
| 863 | vmcase(OP_GETTABUP) { | 866 | vmcase(OP_GETTABUP) { |
| @@ -873,8 +876,8 @@ void luaV_execute (lua_State *L) { | |||
| 873 | } | 876 | } |
| 874 | vmcase(OP_GETTABLE) { | 877 | vmcase(OP_GETTABLE) { |
| 875 | const TValue *slot; | 878 | const TValue *slot; |
| 876 | StkId rb = RB(i); | 879 | TValue *rb = vRB(i); |
| 877 | TValue *rc = RC(i); | 880 | TValue *rc = vRC(i); |
| 878 | lua_Unsigned n; | 881 | lua_Unsigned n; |
| 879 | if (ttisinteger(rc) /* fast track for integers? */ | 882 | if (ttisinteger(rc) /* fast track for integers? */ |
| 880 | ? (n = ivalue(rc), luaV_fastgeti(L, rb, n, slot)) | 883 | ? (n = ivalue(rc), luaV_fastgeti(L, rb, n, slot)) |
| @@ -887,7 +890,7 @@ void luaV_execute (lua_State *L) { | |||
| 887 | } | 890 | } |
| 888 | vmcase(OP_GETI) { | 891 | vmcase(OP_GETI) { |
| 889 | const TValue *slot; | 892 | const TValue *slot; |
| 890 | StkId rb = RB(i); | 893 | TValue *rb = vRB(i); |
| 891 | int c = GETARG_C(i); | 894 | int c = GETARG_C(i); |
| 892 | if (luaV_fastgeti(L, rb, c, slot)) { | 895 | if (luaV_fastgeti(L, rb, c, slot)) { |
| 893 | setobj2s(L, ra, slot); | 896 | setobj2s(L, ra, slot); |
| @@ -901,7 +904,7 @@ void luaV_execute (lua_State *L) { | |||
| 901 | } | 904 | } |
| 902 | vmcase(OP_GETFIELD) { | 905 | vmcase(OP_GETFIELD) { |
| 903 | const TValue *slot; | 906 | const TValue *slot; |
| 904 | StkId rb = RB(i); | 907 | TValue *rb = vRB(i); |
| 905 | TValue *rc = KC(i); | 908 | TValue *rc = KC(i); |
| 906 | TString *key = tsvalue(rc); /* key must be a string */ | 909 | TString *key = tsvalue(rc); /* key must be a string */ |
| 907 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { | 910 | if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) { |
| @@ -925,29 +928,29 @@ void luaV_execute (lua_State *L) { | |||
| 925 | } | 928 | } |
| 926 | vmcase(OP_SETTABLE) { | 929 | vmcase(OP_SETTABLE) { |
| 927 | const TValue *slot; | 930 | const TValue *slot; |
| 928 | TValue *rb = RB(i); /* key (table is in 'ra') */ | 931 | TValue *rb = vRB(i); /* key (table is in 'ra') */ |
| 929 | TValue *rc = RKC(i); /* value */ | 932 | TValue *rc = RKC(i); /* value */ |
| 930 | lua_Unsigned n; | 933 | lua_Unsigned n; |
| 931 | if (ttisinteger(rb) /* fast track for integers? */ | 934 | if (ttisinteger(rb) /* fast track for integers? */ |
| 932 | ? (n = ivalue(rb), luaV_fastgeti(L, ra, n, slot)) | 935 | ? (n = ivalue(rb), luaV_fastgeti(L, s2v(ra), n, slot)) |
| 933 | : luaV_fastget(L, ra, rb, slot, luaH_get)) { | 936 | : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) { |
| 934 | luaV_finishfastset(L, ra, slot, rc); | 937 | luaV_finishfastset(L, s2v(ra), slot, rc); |
| 935 | } | 938 | } |
| 936 | else | 939 | else |
| 937 | Protect(luaV_finishset(L, ra, rb, rc, slot)); | 940 | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); |
| 938 | vmbreak; | 941 | vmbreak; |
| 939 | } | 942 | } |
| 940 | vmcase(OP_SETI) { | 943 | vmcase(OP_SETI) { |
| 941 | const TValue *slot; | 944 | const TValue *slot; |
| 942 | int c = GETARG_B(i); | 945 | int c = GETARG_B(i); |
| 943 | TValue *rc = RKC(i); | 946 | TValue *rc = RKC(i); |
| 944 | if (luaV_fastgeti(L, ra, c, slot)) { | 947 | if (luaV_fastgeti(L, s2v(ra), c, slot)) { |
| 945 | luaV_finishfastset(L, ra, slot, rc); | 948 | luaV_finishfastset(L, s2v(ra), slot, rc); |
| 946 | } | 949 | } |
| 947 | else { | 950 | else { |
| 948 | TValue key; | 951 | TValue key; |
| 949 | setivalue(&key, c); | 952 | setivalue(&key, c); |
| 950 | Protect(luaV_finishset(L, ra, &key, rc, slot)); | 953 | Protect(luaV_finishset(L, s2v(ra), &key, rc, slot)); |
| 951 | } | 954 | } |
| 952 | vmbreak; | 955 | vmbreak; |
| 953 | } | 956 | } |
| @@ -956,11 +959,11 @@ void luaV_execute (lua_State *L) { | |||
| 956 | TValue *rb = KB(i); | 959 | TValue *rb = KB(i); |
| 957 | TValue *rc = RKC(i); | 960 | TValue *rc = RKC(i); |
| 958 | TString *key = tsvalue(rb); /* key must be a string */ | 961 | TString *key = tsvalue(rb); /* key must be a string */ |
| 959 | if (luaV_fastget(L, ra, key, slot, luaH_getshortstr)) { | 962 | if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { |
| 960 | luaV_finishfastset(L, ra, slot, rc); | 963 | luaV_finishfastset(L, s2v(ra), slot, rc); |
| 961 | } | 964 | } |
| 962 | else | 965 | else |
| 963 | Protect(luaV_finishset(L, ra, rb, rc, slot)); | 966 | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); |
| 964 | vmbreak; | 967 | vmbreak; |
| 965 | } | 968 | } |
| 966 | vmcase(OP_NEWTABLE) { | 969 | vmcase(OP_NEWTABLE) { |
| @@ -969,7 +972,7 @@ void luaV_execute (lua_State *L) { | |||
| 969 | Table *t; | 972 | Table *t; |
| 970 | savepc(L); /* in case of allocation errors */ | 973 | savepc(L); /* in case of allocation errors */ |
| 971 | t = luaH_new(L); | 974 | t = luaH_new(L); |
| 972 | sethvalue(L, ra, t); | 975 | sethvalue2s(L, ra, t); |
| 973 | if (b != 0 || c != 0) | 976 | if (b != 0 || c != 0) |
| 974 | luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c)); | 977 | luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c)); |
| 975 | checkGC(L, ra + 1); | 978 | checkGC(L, ra + 1); |
| @@ -977,10 +980,10 @@ void luaV_execute (lua_State *L) { | |||
| 977 | } | 980 | } |
| 978 | vmcase(OP_SELF) { | 981 | vmcase(OP_SELF) { |
| 979 | const TValue *slot; | 982 | const TValue *slot; |
| 980 | StkId rb = RB(i); | 983 | TValue *rb = vRB(i); |
| 981 | TValue *rc = RKC(i); | 984 | TValue *rc = RKC(i); |
| 982 | TString *key = tsvalue(rc); /* key must be a string */ | 985 | TString *key = tsvalue(rc); /* key must be a string */ |
| 983 | setobjs2s(L, ra + 1, rb); | 986 | setobj2s(L, ra + 1, rb); |
| 984 | if (luaV_fastget(L, rb, key, slot, luaH_getstr)) { | 987 | if (luaV_fastget(L, rb, key, slot, luaH_getstr)) { |
| 985 | setobj2s(L, ra, slot); | 988 | setobj2s(L, ra, slot); |
| 986 | } | 989 | } |
| @@ -988,14 +991,14 @@ void luaV_execute (lua_State *L) { | |||
| 988 | vmbreak; | 991 | vmbreak; |
| 989 | } | 992 | } |
| 990 | vmcase(OP_ADDI) { | 993 | vmcase(OP_ADDI) { |
| 991 | TValue *rb = RB(i); | 994 | TValue *rb = vRB(i); |
| 992 | int ic = GETARG_C(i); | 995 | int ic = GETARG_C(i); |
| 993 | lua_Number nb; | 996 | lua_Number nb; |
| 994 | if (ttisinteger(rb)) { | 997 | if (ttisinteger(rb)) { |
| 995 | setivalue(ra, intop(+, ivalue(rb), ic)); | 998 | setivalue(s2v(ra), intop(+, ivalue(rb), ic)); |
| 996 | } | 999 | } |
| 997 | else if (tonumber(rb, &nb)) { | 1000 | else if (tonumber(rb, &nb)) { |
| 998 | setfltvalue(ra, luai_numadd(L, nb, cast_num(ic))); | 1001 | setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic))); |
| 999 | } | 1002 | } |
| 1000 | else { | 1003 | else { |
| 1001 | TValue aux; TValue *rc; | 1004 | TValue aux; TValue *rc; |
| @@ -1014,10 +1017,10 @@ void luaV_execute (lua_State *L) { | |||
| 1014 | lua_Number nb; lua_Number nc; | 1017 | lua_Number nb; lua_Number nc; |
| 1015 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1018 | if (ttisinteger(rb) && ttisinteger(rc)) { |
| 1016 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1019 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
| 1017 | setivalue(ra, intop(+, ib, ic)); | 1020 | setivalue(s2v(ra), intop(+, ib, ic)); |
| 1018 | } | 1021 | } |
| 1019 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1022 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1020 | setfltvalue(ra, luai_numadd(L, nb, nc)); | 1023 | setfltvalue(s2v(ra), luai_numadd(L, nb, nc)); |
| 1021 | } | 1024 | } |
| 1022 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); } | 1025 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); } |
| 1023 | vmbreak; | 1026 | vmbreak; |
| @@ -1028,10 +1031,10 @@ void luaV_execute (lua_State *L) { | |||
| 1028 | lua_Number nb; lua_Number nc; | 1031 | lua_Number nb; lua_Number nc; |
| 1029 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1032 | if (ttisinteger(rb) && ttisinteger(rc)) { |
| 1030 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1033 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
| 1031 | setivalue(ra, intop(-, ib, ic)); | 1034 | setivalue(s2v(ra), intop(-, ib, ic)); |
| 1032 | } | 1035 | } |
| 1033 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1036 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1034 | setfltvalue(ra, luai_numsub(L, nb, nc)); | 1037 | setfltvalue(s2v(ra), luai_numsub(L, nb, nc)); |
| 1035 | } | 1038 | } |
| 1036 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); } | 1039 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); } |
| 1037 | vmbreak; | 1040 | vmbreak; |
| @@ -1042,10 +1045,10 @@ void luaV_execute (lua_State *L) { | |||
| 1042 | lua_Number nb; lua_Number nc; | 1045 | lua_Number nb; lua_Number nc; |
| 1043 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1046 | if (ttisinteger(rb) && ttisinteger(rc)) { |
| 1044 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1047 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
| 1045 | setivalue(ra, intop(*, ib, ic)); | 1048 | setivalue(s2v(ra), intop(*, ib, ic)); |
| 1046 | } | 1049 | } |
| 1047 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1050 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1048 | setfltvalue(ra, luai_nummul(L, nb, nc)); | 1051 | setfltvalue(s2v(ra), luai_nummul(L, nb, nc)); |
| 1049 | } | 1052 | } |
| 1050 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); } | 1053 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); } |
| 1051 | vmbreak; | 1054 | vmbreak; |
| @@ -1055,7 +1058,7 @@ void luaV_execute (lua_State *L) { | |||
| 1055 | TValue *rc = RKC(i); | 1058 | TValue *rc = RKC(i); |
| 1056 | lua_Number nb; lua_Number nc; | 1059 | lua_Number nb; lua_Number nc; |
| 1057 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1060 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1058 | setfltvalue(ra, luai_numdiv(L, nb, nc)); | 1061 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); |
| 1059 | } | 1062 | } |
| 1060 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); } | 1063 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); } |
| 1061 | vmbreak; | 1064 | vmbreak; |
| @@ -1065,7 +1068,7 @@ void luaV_execute (lua_State *L) { | |||
| 1065 | TValue *rc = RKC(i); | 1068 | TValue *rc = RKC(i); |
| 1066 | lua_Integer ib; lua_Integer ic; | 1069 | lua_Integer ib; lua_Integer ic; |
| 1067 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1070 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
| 1068 | setivalue(ra, intop(&, ib, ic)); | 1071 | setivalue(s2v(ra), intop(&, ib, ic)); |
| 1069 | } | 1072 | } |
| 1070 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); } | 1073 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); } |
| 1071 | vmbreak; | 1074 | vmbreak; |
| @@ -1075,7 +1078,7 @@ void luaV_execute (lua_State *L) { | |||
| 1075 | TValue *rc = RKC(i); | 1078 | TValue *rc = RKC(i); |
| 1076 | lua_Integer ib; lua_Integer ic; | 1079 | lua_Integer ib; lua_Integer ic; |
| 1077 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1080 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
| 1078 | setivalue(ra, intop(|, ib, ic)); | 1081 | setivalue(s2v(ra), intop(|, ib, ic)); |
| 1079 | } | 1082 | } |
| 1080 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); } | 1083 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); } |
| 1081 | vmbreak; | 1084 | vmbreak; |
| @@ -1085,7 +1088,7 @@ void luaV_execute (lua_State *L) { | |||
| 1085 | TValue *rc = RKC(i); | 1088 | TValue *rc = RKC(i); |
| 1086 | lua_Integer ib; lua_Integer ic; | 1089 | lua_Integer ib; lua_Integer ic; |
| 1087 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1090 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
| 1088 | setivalue(ra, intop(^, ib, ic)); | 1091 | setivalue(s2v(ra), intop(^, ib, ic)); |
| 1089 | } | 1092 | } |
| 1090 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); } | 1093 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); } |
| 1091 | vmbreak; | 1094 | vmbreak; |
| @@ -1095,7 +1098,7 @@ void luaV_execute (lua_State *L) { | |||
| 1095 | TValue *rc = RKC(i); | 1098 | TValue *rc = RKC(i); |
| 1096 | lua_Integer ib; lua_Integer ic; | 1099 | lua_Integer ib; lua_Integer ic; |
| 1097 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1100 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
| 1098 | setivalue(ra, luaV_shiftl(ib, ic)); | 1101 | setivalue(s2v(ra), luaV_shiftl(ib, ic)); |
| 1099 | } | 1102 | } |
| 1100 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); } | 1103 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); } |
| 1101 | vmbreak; | 1104 | vmbreak; |
| @@ -1105,7 +1108,7 @@ void luaV_execute (lua_State *L) { | |||
| 1105 | TValue *rc = RKC(i); | 1108 | TValue *rc = RKC(i); |
| 1106 | lua_Integer ib; lua_Integer ic; | 1109 | lua_Integer ib; lua_Integer ic; |
| 1107 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { | 1110 | if (tointeger(rb, &ib) && tointeger(rc, &ic)) { |
| 1108 | setivalue(ra, luaV_shiftl(ib, -ic)); | 1111 | setivalue(s2v(ra), luaV_shiftl(ib, -ic)); |
| 1109 | } | 1112 | } |
| 1110 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); } | 1113 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); } |
| 1111 | vmbreak; | 1114 | vmbreak; |
| @@ -1116,12 +1119,12 @@ void luaV_execute (lua_State *L) { | |||
| 1116 | lua_Number nb; lua_Number nc; | 1119 | lua_Number nb; lua_Number nc; |
| 1117 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1120 | if (ttisinteger(rb) && ttisinteger(rc)) { |
| 1118 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1121 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
| 1119 | setivalue(ra, luaV_mod(L, ib, ic)); | 1122 | setivalue(s2v(ra), luaV_mod(L, ib, ic)); |
| 1120 | } | 1123 | } |
| 1121 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1124 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1122 | lua_Number m; | 1125 | lua_Number m; |
| 1123 | luai_nummod(L, nb, nc, m); | 1126 | luai_nummod(L, nb, nc, m); |
| 1124 | setfltvalue(ra, m); | 1127 | setfltvalue(s2v(ra), m); |
| 1125 | } | 1128 | } |
| 1126 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } | 1129 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } |
| 1127 | vmbreak; | 1130 | vmbreak; |
| @@ -1132,10 +1135,10 @@ void luaV_execute (lua_State *L) { | |||
| 1132 | lua_Number nb; lua_Number nc; | 1135 | lua_Number nb; lua_Number nc; |
| 1133 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1136 | if (ttisinteger(rb) && ttisinteger(rc)) { |
| 1134 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1137 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
| 1135 | setivalue(ra, luaV_div(L, ib, ic)); | 1138 | setivalue(s2v(ra), luaV_div(L, ib, ic)); |
| 1136 | } | 1139 | } |
| 1137 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1140 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1138 | setfltvalue(ra, luai_numidiv(L, nb, nc)); | 1141 | setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); |
| 1139 | } | 1142 | } |
| 1140 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); } | 1143 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); } |
| 1141 | vmbreak; | 1144 | vmbreak; |
| @@ -1145,20 +1148,20 @@ void luaV_execute (lua_State *L) { | |||
| 1145 | TValue *rc = RKC(i); | 1148 | TValue *rc = RKC(i); |
| 1146 | lua_Number nb; lua_Number nc; | 1149 | lua_Number nb; lua_Number nc; |
| 1147 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 1150 | if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
| 1148 | setfltvalue(ra, luai_numpow(L, nb, nc)); | 1151 | setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); |
| 1149 | } | 1152 | } |
| 1150 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); } | 1153 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); } |
| 1151 | vmbreak; | 1154 | vmbreak; |
| 1152 | } | 1155 | } |
| 1153 | vmcase(OP_UNM) { | 1156 | vmcase(OP_UNM) { |
| 1154 | TValue *rb = RB(i); | 1157 | TValue *rb = vRB(i); |
| 1155 | lua_Number nb; | 1158 | lua_Number nb; |
| 1156 | if (ttisinteger(rb)) { | 1159 | if (ttisinteger(rb)) { |
| 1157 | lua_Integer ib = ivalue(rb); | 1160 | lua_Integer ib = ivalue(rb); |
| 1158 | setivalue(ra, intop(-, 0, ib)); | 1161 | setivalue(s2v(ra), intop(-, 0, ib)); |
| 1159 | } | 1162 | } |
| 1160 | else if (tonumber(rb, &nb)) { | 1163 | else if (tonumber(rb, &nb)) { |
| 1161 | setfltvalue(ra, luai_numunm(L, nb)); | 1164 | setfltvalue(s2v(ra), luai_numunm(L, nb)); |
| 1162 | } | 1165 | } |
| 1163 | else { | 1166 | else { |
| 1164 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); | 1167 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); |
| @@ -1166,10 +1169,10 @@ void luaV_execute (lua_State *L) { | |||
| 1166 | vmbreak; | 1169 | vmbreak; |
| 1167 | } | 1170 | } |
| 1168 | vmcase(OP_BNOT) { | 1171 | vmcase(OP_BNOT) { |
| 1169 | TValue *rb = RB(i); | 1172 | TValue *rb = vRB(i); |
| 1170 | lua_Integer ib; | 1173 | lua_Integer ib; |
| 1171 | if (tointeger(rb, &ib)) { | 1174 | if (tointeger(rb, &ib)) { |
| 1172 | setivalue(ra, intop(^, ~l_castS2U(0), ib)); | 1175 | setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib)); |
| 1173 | } | 1176 | } |
| 1174 | else { | 1177 | else { |
| 1175 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); | 1178 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); |
| @@ -1177,13 +1180,13 @@ void luaV_execute (lua_State *L) { | |||
| 1177 | vmbreak; | 1180 | vmbreak; |
| 1178 | } | 1181 | } |
| 1179 | vmcase(OP_NOT) { | 1182 | vmcase(OP_NOT) { |
| 1180 | TValue *rb = RB(i); | 1183 | TValue *rb = vRB(i); |
| 1181 | int res = l_isfalse(rb); /* next assignment may change this value */ | 1184 | int res = l_isfalse(rb); /* next assignment may change this value */ |
| 1182 | setbvalue(ra, res); | 1185 | setbvalue(s2v(ra), res); |
| 1183 | vmbreak; | 1186 | vmbreak; |
| 1184 | } | 1187 | } |
| 1185 | vmcase(OP_LEN) { | 1188 | vmcase(OP_LEN) { |
| 1186 | Protect(luaV_objlen(L, ra, RB(i))); | 1189 | Protect(luaV_objlen(L, ra, vRB(i))); |
| 1187 | vmbreak; | 1190 | vmbreak; |
| 1188 | } | 1191 | } |
| 1189 | vmcase(OP_CONCAT) { | 1192 | vmcase(OP_CONCAT) { |
| @@ -1245,18 +1248,18 @@ void luaV_execute (lua_State *L) { | |||
| 1245 | vmbreak; | 1248 | vmbreak; |
| 1246 | } | 1249 | } |
| 1247 | vmcase(OP_TEST) { | 1250 | vmcase(OP_TEST) { |
| 1248 | if (GETARG_C(i) ? l_isfalse(ra) : !l_isfalse(ra)) | 1251 | if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra))) |
| 1249 | pc++; | 1252 | pc++; |
| 1250 | else | 1253 | else |
| 1251 | donextjump(ci); | 1254 | donextjump(ci); |
| 1252 | vmbreak; | 1255 | vmbreak; |
| 1253 | } | 1256 | } |
| 1254 | vmcase(OP_TESTSET) { | 1257 | vmcase(OP_TESTSET) { |
| 1255 | TValue *rb = RB(i); | 1258 | TValue *rb = vRB(i); |
| 1256 | if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb)) | 1259 | if (GETARG_C(i) ? l_isfalse(rb) : !l_isfalse(rb)) |
| 1257 | pc++; | 1260 | pc++; |
| 1258 | else { | 1261 | else { |
| 1259 | setobjs2s(L, ra, rb); | 1262 | setobj2s(L, ra, rb); |
| 1260 | donextjump(ci); | 1263 | donextjump(ci); |
| 1261 | } | 1264 | } |
| 1262 | vmbreak; | 1265 | vmbreak; |
| @@ -1295,7 +1298,7 @@ void luaV_execute (lua_State *L) { | |||
| 1295 | StkId nfunc = nci->func; /* called function */ | 1298 | StkId nfunc = nci->func; /* called function */ |
| 1296 | StkId ofunc = oci->func; /* caller function */ | 1299 | StkId ofunc = oci->func; /* caller function */ |
| 1297 | /* last stack slot filled by 'precall' */ | 1300 | /* last stack slot filled by 'precall' */ |
| 1298 | StkId lim = nci->func + 1 + getproto(nfunc)->numparams; | 1301 | StkId lim = nci->func + 1 + getproto(s2v(nfunc))->numparams; |
| 1299 | int aux; | 1302 | int aux; |
| 1300 | /* close all upvalues from previous call */ | 1303 | /* close all upvalues from previous call */ |
| 1301 | if (cl->p->sizep > 0) luaF_close(L, oci->func + 1); | 1304 | if (cl->p->sizep > 0) luaF_close(L, oci->func + 1); |
| @@ -1306,7 +1309,8 @@ void luaV_execute (lua_State *L) { | |||
| 1306 | oci->u.l.savedpc = nci->u.l.savedpc; | 1309 | oci->u.l.savedpc = nci->u.l.savedpc; |
| 1307 | oci->callstatus |= CIST_TAIL; /* function was tail called */ | 1310 | oci->callstatus |= CIST_TAIL; /* function was tail called */ |
| 1308 | ci = L->ci = oci; /* remove new frame */ | 1311 | ci = L->ci = oci; /* remove new frame */ |
| 1309 | lua_assert(L->top == oci->func + 1 + getproto(ofunc)->maxstacksize); | 1312 | lua_assert(L->top == |
| 1313 | oci->func + 1 + getproto(s2v(ofunc))->maxstacksize); | ||
| 1310 | goto newframe; /* restart luaV_execute over new Lua function */ | 1314 | goto newframe; /* restart luaV_execute over new Lua function */ |
| 1311 | } | 1315 | } |
| 1312 | vmbreak; | 1316 | vmbreak; |
| @@ -1327,34 +1331,35 @@ void luaV_execute (lua_State *L) { | |||
| 1327 | } | 1331 | } |
| 1328 | } | 1332 | } |
| 1329 | vmcase(OP_FORLOOP) { | 1333 | vmcase(OP_FORLOOP) { |
| 1330 | if (ttisinteger(ra)) { /* integer loop? */ | 1334 | if (ttisinteger(s2v(ra))) { /* integer loop? */ |
| 1331 | lua_Integer step = ivalue(ra + 2); | 1335 | lua_Integer step = ivalue(s2v(ra + 2)); |
| 1332 | lua_Integer idx = intop(+, ivalue(ra), step); /* increment index */ | 1336 | lua_Integer idx = intop(+, ivalue(s2v(ra)), step); /* increment index */ |
| 1333 | lua_Integer limit = ivalue(ra + 1); | 1337 | lua_Integer limit = ivalue(s2v(ra + 1)); |
| 1334 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { | 1338 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { |
| 1335 | pc += GETARG_sBx(i); /* jump back */ | 1339 | pc += GETARG_sBx(i); /* jump back */ |
| 1336 | chgivalue(ra, idx); /* update internal index... */ | 1340 | chgivalue(s2v(ra), idx); /* update internal index... */ |
| 1337 | setivalue(ra + 3, idx); /* ...and external index */ | 1341 | setivalue(s2v(ra + 3), idx); /* ...and external index */ |
| 1338 | } | 1342 | } |
| 1339 | } | 1343 | } |
| 1340 | else { /* floating loop */ | 1344 | else { /* floating loop */ |
| 1341 | lua_Number step = fltvalue(ra + 2); | 1345 | lua_Number step = fltvalue(s2v(ra + 2)); |
| 1342 | lua_Number idx = luai_numadd(L, fltvalue(ra), step); /* inc. index */ | 1346 | lua_Number limit = fltvalue(s2v(ra + 1)); |
| 1343 | lua_Number limit = fltvalue(ra + 1); | 1347 | lua_Number idx = fltvalue(s2v(ra)); |
| 1348 | idx = luai_numadd(L, idx, step); /* inc. index */ | ||
| 1344 | if (luai_numlt(0, step) ? luai_numle(idx, limit) | 1349 | if (luai_numlt(0, step) ? luai_numle(idx, limit) |
| 1345 | : luai_numle(limit, idx)) { | 1350 | : luai_numle(limit, idx)) { |
| 1346 | pc += GETARG_sBx(i); /* jump back */ | 1351 | pc += GETARG_sBx(i); /* jump back */ |
| 1347 | chgfltvalue(ra, idx); /* update internal index... */ | 1352 | chgfltvalue(s2v(ra), idx); /* update internal index... */ |
| 1348 | setfltvalue(ra + 3, idx); /* ...and external index */ | 1353 | setfltvalue(s2v(ra + 3), idx); /* ...and external index */ |
| 1349 | } | 1354 | } |
| 1350 | } | 1355 | } |
| 1351 | updatemask(L); | 1356 | updatemask(L); |
| 1352 | vmbreak; | 1357 | vmbreak; |
| 1353 | } | 1358 | } |
| 1354 | vmcase(OP_FORPREP) { | 1359 | vmcase(OP_FORPREP) { |
| 1355 | TValue *init = ra; | 1360 | TValue *init = s2v(ra); |
| 1356 | TValue *plimit = ra + 1; | 1361 | TValue *plimit = s2v(ra + 1); |
| 1357 | TValue *pstep = ra + 2; | 1362 | TValue *pstep = s2v(ra + 2); |
| 1358 | lua_Integer ilimit; | 1363 | lua_Integer ilimit; |
| 1359 | int stopnow; | 1364 | int stopnow; |
| 1360 | if (ttisinteger(init) && ttisinteger(pstep) && | 1365 | if (ttisinteger(init) && ttisinteger(pstep) && |
| @@ -1395,7 +1400,7 @@ void luaV_execute (lua_State *L) { | |||
| 1395 | } | 1400 | } |
| 1396 | vmcase(OP_TFORLOOP) { | 1401 | vmcase(OP_TFORLOOP) { |
| 1397 | l_tforloop: | 1402 | l_tforloop: |
| 1398 | if (!ttisnil(ra + 1)) { /* continue loop? */ | 1403 | if (!ttisnil(s2v(ra + 1))) { /* continue loop? */ |
| 1399 | setobjs2s(L, ra, ra + 1); /* save control variable */ | 1404 | setobjs2s(L, ra, ra + 1); /* save control variable */ |
| 1400 | pc += GETARG_sBx(i); /* jump back */ | 1405 | pc += GETARG_sBx(i); /* jump back */ |
| 1401 | } | 1406 | } |
| @@ -1411,13 +1416,13 @@ void luaV_execute (lua_State *L) { | |||
| 1411 | lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); | 1416 | lua_assert(GET_OPCODE(*pc) == OP_EXTRAARG); |
| 1412 | c = GETARG_Ax(*pc++); | 1417 | c = GETARG_Ax(*pc++); |
| 1413 | } | 1418 | } |
| 1414 | h = hvalue(ra); | 1419 | h = hvalue(s2v(ra)); |
| 1415 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; | 1420 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; |
| 1416 | savepc(L); /* in case of allocation errors */ | 1421 | savepc(L); /* in case of allocation errors */ |
| 1417 | if (last > h->sizearray) /* needs more space? */ | 1422 | if (last > h->sizearray) /* needs more space? */ |
| 1418 | luaH_resizearray(L, h, last); /* preallocate it at once */ | 1423 | luaH_resizearray(L, h, last); /* preallocate it at once */ |
| 1419 | for (; n > 0; n--) { | 1424 | for (; n > 0; n--) { |
| 1420 | TValue *val = ra + n; | 1425 | TValue *val = s2v(ra + n); |
| 1421 | setobj2t(L, &h->array[last - 1], val); | 1426 | setobj2t(L, &h->array[last - 1], val); |
| 1422 | last--; | 1427 | last--; |
| 1423 | luaC_barrierback(L, h, val); | 1428 | luaC_barrierback(L, h, val); |
| @@ -1433,13 +1438,13 @@ void luaV_execute (lua_State *L) { | |||
| 1433 | pushclosure(L, p, cl->upvals, base, ra); /* create a new one */ | 1438 | pushclosure(L, p, cl->upvals, base, ra); /* create a new one */ |
| 1434 | } | 1439 | } |
| 1435 | else | 1440 | else |
| 1436 | setclLvalue(L, ra, ncl); /* push cashed closure */ | 1441 | setclLvalue2s(L, ra, ncl); /* push cashed closure */ |
| 1437 | checkGC(L, ra + 1); | 1442 | checkGC(L, ra + 1); |
| 1438 | vmbreak; | 1443 | vmbreak; |
| 1439 | } | 1444 | } |
| 1440 | vmcase(OP_VARARG) { | 1445 | vmcase(OP_VARARG) { |
| 1441 | int b = GETARG_B(i) - 1; /* required results */ | 1446 | int b = GETARG_B(i) - 1; /* required results */ |
| 1442 | StkId vtab = base + cl->p->numparams - 1; /* vararg table */ | 1447 | TValue *vtab = s2v(base + cl->p->numparams - 1); /* vararg table */ |
| 1443 | Protect(luaT_getvarargs(L, vtab, ra, b)); | 1448 | Protect(luaT_getvarargs(L, vtab, ra, b)); |
| 1444 | vmbreak; | 1449 | vmbreak; |
| 1445 | } | 1450 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.h,v 2.43 2017/06/01 20:23:27 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 2.44 2017/06/09 19:16:41 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 | */ |
| @@ -93,7 +93,7 @@ LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); | |||
| 93 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, | 93 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, |
| 94 | StkId val, const TValue *slot); | 94 | StkId val, const TValue *slot); |
| 95 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | 95 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |
| 96 | StkId val, const TValue *slot); | 96 | TValue *val, const TValue *slot); |
| 97 | LUAI_FUNC void luaV_finishOp (lua_State *L); | 97 | LUAI_FUNC void luaV_finishOp (lua_State *L); |
| 98 | LUAI_FUNC void luaV_execute (lua_State *L); | 98 | LUAI_FUNC void luaV_execute (lua_State *L); |
| 99 | LUAI_FUNC void luaV_concat (lua_State *L, int total); | 99 | LUAI_FUNC void luaV_concat (lua_State *L, int total); |
